xyzio

Posts Tagged ‘header

Set User-Agent for Python requests library

leave a comment »

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)

Written by M Kapoor

February 4, 2017 at 1:29 am

Posted in python

Tagged with , ,