As more and more website use https instead of http, we'll encounter 403 error when get content with requests modules. To solve it, the easiest way is simulating browser to access.
OS: Debian 9
OS: Debian 9
Python: 3.5.3
Module: requests
setup headers as 1st step:
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3)\
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36'}
then add headers as parameter:
res = requests.get(xqurl, headers=headers)
Below is my example to get stock price in dictionary from a https website:
Comments
Post a Comment