Changing user agent on urllib2.urlopen

后端 未结 9 2189
感动是毒
感动是毒 2020-11-22 13:59

How can I download a webpage with a user agent other than the default one on urllib2.urlopen?

9条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-22 14:55

    Try this :

    html_source_code = requests.get("http://www.example.com/",
                       headers={'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.107 Safari/537.36',
                                'Upgrade-Insecure-Requests': '1',
                                'x-runtime': '148ms'}, 
                       allow_redirects=True).content
    

提交回复
热议问题