November 2017
Intermediate to advanced
226 pages
5h 59m
English
Let's try downloading a simple image file with the requests module. Open Python 2:
>>> import requests
>>> response = requests.get("https://rejahrehim.com/images/me/rejah.png")
>>> with open("me.png",'wb') as file:
... file.write(response.content)
If it's a large file, the response.content will be a large string and won't be able to save all the data in a single string. Here, we use the iter_content method to load the data in chunks.
response = requests.get("https://rejahrehim.com/images/me/rejah.png", ...Read now
Unlock full access