February 2019
Intermediate to advanced
672 pages
16h 50m
English
Let's look at an example usage of the module. If you already have the code for this book downloaded from the GitHub page, go ahead and navigate to the Chapter12 folder. Let's take a look at the example1.py file, as shown in the following code:
# Chapter12/example1.pyimport requestsurl = 'http://www.google.com'res = requests.get(url)print(res.status_code)print(res.headers)with open('google.html', 'w') as f: f.write(res.text)print('Done.')
In this example, we are using the requests module to download the HTML code of the web page, www.google.com. The requests.get() method sends a GET request method to url and we store the response to the res variable. After checking the status and headers of the response by printing ...