hi,各位好,我在爬大众点评的这个网页http://www.dianping.com/search/keyword/2/75_%E6%96%B0%E4%B8%9C%E6%96%B9,用的request包获取网页源码,header主要添加了user-agent和cookie,但为什么总是返回错误?求助,谢谢各位了!
PS:用curl可以返回正常的源码,没有被封IP
import requests
def gethtml(url, headers):
html = requests.get(url, headers = headers)
html.encoding = 'utf-8'
return html.text
head = {'User_Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2723.3 Safari/537.36',
'Cookie': 'PHOENIX_ID=0a650c81-154a0633f47-a97843; _hc.v="\"e27e18eb-3a3d-4b40-b06a-cbe624c96048.1462979739\""; s_ViewType=10; JSESSIONID=877B00919AD417544F72F5A9953E54B4; aburl=1; cy=2; cye=beijing'}
url = 'http://www.dianping.com/search/keyword/2/75_%E6%96%B0%E4%B8%9C%E6%96%B9'
html = gethtml(url, head)
print(html)
伊谢尔伦2017-04-17 17:45:45
해결되었습니다 {'Accept': 'application/json, text/javascript'}
를 헤더에 추가하시면 정상적으로 복귀하실 수 있습니다