Requests

Download file from internet and save it

import requests
res = requests.get('http://web-profile.net/readme.html')
# res = requests.get('https://www.google.com/search?q=vitalii')
try:
    res.raise_for_status()
except Exception as exc:
    print('There was a problem: %s' % (exc))
print(type(res)) # <class 'requests.models.Response'>
print(res.status_code == requests.codes.ok) # True
print(len(res.text)) # 178981
print(res.text[:250]) # <!DOCTYPE html><html><head>...
readmeFile = open('readme.html', 'wb')
for chunk in res.iter_content(100000):
    readmeFile.write(chunk) # 7433
readmeFile.close()

Installing Requests module:
pip install requests

Leave a Reply

Your email address will not be published. Required fields are marked *