爬虫伪装成浏览器访问

 
  
headers = {
  "user-agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36"
}
url = 'http://weixin.sogou.com/weixin?type=2&s_from=input&query={}'.format('%E9%9B%85%E8%AF%BA%E4%BF%A1%E5%85%AC%E5%8F%B8%E7%9B%B8%E5%85%B3%E8%B4%9F%E8%B4%A3%E4%BA%BA%E8%A1%A8%E7%A4%BA%2C%E5%BD%93%E6%97%B6%E8%80%83%E8%99%91%E6%98%AF%E6%B8%A9%E5%85%88%E7%94%9F%E6%98%AF%E5%85%AC%E5%8F%B8%E5%91%98%E5%B7%A5')
content = requests.post(url,headers=headers).text

用httpbin.org得到user-agent。

你可能感兴趣的:(日常问题)