Posts Tagged ‘requests’
Set User-Agent for Python requests library
Some sites don’t allow page access if the User-Agent isn’t set. headers is a hash and can hold additional header tokens.
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36'} resp = requests.get(url, headers=headers)
Download and save file using Python Requests
Download and save a file using the Python requests library.
Where:
url = URL to download
filename = Name of local file for url
import requests url = '' response = requests.get(url) with open(filename, 'wb') as f: f.write(response.content)