Python Tutorial : HTTP requests to import files from the web
Skills:
Python for Data70%
Key Takeaways
This video tutorial demonstrates how to use Python's URL Lib and requests library to import files from the web using HTTP requests, specifically GET requests, to retrieve HTML data from web pages.
Full Transcript
Congrats on importing your first web data in order to import files from the web we use the URL retrieve function from URL Lib requests let's now unpack this a bit and in the process understand a few things about how the internet works URL stands for Uniform or universal resource locator and all they really are are references to web resources the vast majority of urls are web addresses but they can also refer to a few other things such as file transfer protocols ftp and database access will currently focus on those urls that our web addresses or the locations of websites such a URL consists of two parts a protocol identifier HTTP or HTTPS and a resource name such as data count comm the combination of protocol identifier and resource name uniquely specifies the web address to explain URLs i've introduced yet another acronym HTTP which itself stands for hypertext Transfer Protocol Wikipedia provides a great description of a TTP the hypertext Transfer Protocol is an application protocol for distributed collaborative hypermedia information systems HTTP is the foundation of data communication for the worldwide web note that HTTP is a more secure form of HTTP each time you go to our web site you are actually sending an HTTP request to a server this request is known as a get request by far the most common type of HTTP request we are actually performing a get request when using the function URL retrieve the ingenuity of URL retrieved also lies in the fact that it not only makes a get request but also saves the relevant data locally in the following you'll learn how to make more get requests to store web data in your environment in particular you'll figure out how to get the HTML data from a web page HTML stands for hypertext markup language and is the standard markup language for the web to extract the HTML from the Wikipedia homepage for example you import the necessary functions specify the URL package the get request using the function request send the request and catch the response using the function URL open this returns an HTTP response object which has an Associated read method you then apply this read method to the response which returns the HTML as a string which you store in the variable HTML finally you remember to be polite and close the response now we're going to do the same however here we'll use the requests package which provides a wonderful API for making requests according to the requests package website requests allows you to send organic grass-fed HTTP requests without the need for manual labor and the following organizations claim to use requests internally Her Majesty's Government Amazon Google Twilio NPR Obama for America Twitter Sony and federal us institutions that prefer to be unnamed moreover requests is one of the most downloaded Python packages of all time pulling in over 7 million downloads every month all the cool kids are doing it let's now see requests at work here you import the package requests specify the URL package the request send the request and catch the response with a single function requests get and finally you apply the text method to the response which returns the HTML as a string ok that's enough out of me for the time being let's get you hacking away at pulling down some HTML from the web using get requests get coding
Original Description
Want to learn more? Take the full course at https://learn.datacamp.com/courses/intermediate-importing-data-in-python at your own pace. More than a video, you'll learn hands-on coding & quickly apply skills to your daily work.
---
Congrats on importing your first web data! In order to import files from the web, we used the urlretrieve function from urllib dot requests. Lets now unpack this a bit and, in the process, understand a few things about how the internet works.
URL stands for Uniform or Universal Resource Locator and all they really are references to web resources. The vast majority of URLs are web addresses, but they can refer to a few other things, such as file transfer protocols (FTP) and database access. We'll currently focus on those URLs that are web addresses OR the locations of websites.
Such a URL consists of 2 parts, a protocol identifier http or https and a resource name such as datacamp dot com.
The combination of protocol identifier and resource name uniquely specifies the web address!
To explain URLs, I have introduced yet another acronym http, which itself stands for HyperText Transfer Protocol. Wikipedia provides a great description of HTTP.
"The Hypertext Transfer Protocol (HTTP) is an application protocol for distributed, collaborative, hypermedia information systems. HTTP is the foundation of data communication for the World Wide Web."
Note that HTTPS is a more secure form of HTTP. Each time you go to a website, you are actually sending an HTTP request to a server. This request is known as a GET request, by far the most common type of HTTP request.
We are actually performing a GET request when using the function urlretrieve. The ingenuity of urlretrieve also lies in the fact that it not only makes a GET request but also saves the relevant data locally.
In the following, you'll learn how to make more GET requests to store web data in your environment. In particular, you'll figure out how to get the HTML data from a webpage. HTML st
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from DataCamp · DataCamp · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
SQL Server Tutorial: Date manipulation
DataCamp
R Tutorial: Intermediate Interactive Data Visualization with plotly in R
DataCamp
R Tutorial: Adding aesthetics to represent a variable
DataCamp
R Tutorial: Moving Beyond Simple Interactivity
DataCamp
Python Tutorial: Why use ML for marketing? Strategies and use cases
DataCamp
Python Tutorial: Preparation for modeling
DataCamp
Python Tutorial: Machine Learning modeling steps
DataCamp
R Tutorial: The prior model
DataCamp
R Tutorial: Data & the likelihood
DataCamp
R Tutorial: The posterior model
DataCamp
R Tutorial: An Introduction to plotly
DataCamp
R Tutorial: Plotting a single variable
DataCamp
R Tutorial: Bivariate graphics
DataCamp
Python Tutorial: Customer Segmentation in Python
DataCamp
Python Tutorial: Time cohorts
DataCamp
Python Tutorial: Calculate cohort metrics
DataCamp
Python Tutorial: Cohort analysis visualization
DataCamp
R Tutorial: Building Dashboards with flexdashboard
DataCamp
R Tutorial: Anatomy of a flexdashboard
DataCamp
R Tutorial: Layout basics
DataCamp
R Tutorial: Advanced layouts
DataCamp
Python Tutorial: Time Series Analysis in Python
DataCamp
Python Tutorial: Correlation of Two Time Series
DataCamp
Python Tutorial: Simple Linear Regressions
DataCamp
Python Tutorial: Autocorrelation
DataCamp
R Tutorial: The gapminder dataset
DataCamp
R Tutorial: The filter verb
DataCamp
R Tutorial: The arrange verb
DataCamp
R Tutorial: The mutate verb
DataCamp
R Tutorial: What is cluster analysis?
DataCamp
R Tutorial: Distance between two observations
DataCamp
R Tutorial: The importance of scale
DataCamp
R Tutorial: Measuring distance for categorical data
DataCamp
Python Tutorial: Plotting multiple graphs
DataCamp
Python Tutorial: Customizing axes
DataCamp
Python Tutorial: Legends, annotations, & styles
DataCamp
Python Tutorial: Introduction to iterators
DataCamp
Python Tutorial: Playing with iterators
DataCamp
Python Tutorial: Using iterators to load large files into memory
DataCamp
SQL Tutorial: Introduction to Relational Databases in SQL
DataCamp
SQL Tutorial: Tables: At the core of every database
DataCamp
SQL Tutorial: Update your database as the structure changes
DataCamp
Python Tutorial: Classification-Tree Learning
DataCamp
Python Tutorial: Decision-Tree for Classification
DataCamp
Python Tutorial: Decision-Tree for Regression
DataCamp
Python Tutorial: Census Subject Tables
DataCamp
Python Tutorial: Census Geography
DataCamp
Python Tutorial: Using the Census API
DataCamp
R Tutorial: A/B Testing in R
DataCamp
R Tutorial: Baseline Conversion Rates
DataCamp
R Tutorial: Designing an Experiment - Power Analysis
DataCamp
R Tutorial: Introduction to qualitative data
DataCamp
R Tutorial: Understanding your qualitative variables
DataCamp
R Tutorial: Making Better Plots
DataCamp
SQL Tutorial: OLTP and OLAP
DataCamp
SQL Tutorial: Storing data
DataCamp
SQL Tutorial: Database design
DataCamp
Python Tutorial: Introduction to spaCy
DataCamp
Python Tutorial: Statistical Models
DataCamp
Python Tutorial: Rule-based Matching
DataCamp
More on: Python for Data
View skill →Related AI Lessons
⚡
⚡
⚡
⚡
How to prepare TIC teacher exams in Spain with AI (oposiciones 2026)
Dev.to AI
Why I built a simple AI provider wrapper (and you might too)
Dev.to · zhongqiyue
This ChatGPT Prompt Replaced 3 Hours of PowerPoint Work
Medium · AI
This ChatGPT Prompt Replaced 3 Hours of PowerPoint Work
Medium · ChatGPT
🎓
Tutor Explanation
DeepCamp AI