我在页面上输入的是: import requests
head={'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36','Accept-Encoding':'gzip, deflate, sdch'} url='https://diviner.jd.com/diviner?lid=1&p=103003&sku=676676' html=requests.get(url,headers=head) print html.content
但是输出的却一直是
<html> <head><title>500 Internal Server Error</title></head> <body bgcolor="white"> <center>不知道是哪里出现问题了,这个网页我确实能打开的哇,求解答,谢谢
1
misaka19000 2016-10-26 16:13:29 +08:00
很明显请求头部的信息不够,导致了服务器非正常响应
|
2
gayu OP @misaka19000 需要全部加进去么?
|
3
misaka19000 2016-10-26 20:17:35 +08:00
@gayu 应该要,看服务器怎么解析了
|
4
bocy 2016-10-27 14:01:50 +08:00
要传一个 cookie ,可以加在头上,我这里试了一下这个代码可以返回数据
``` import requests head={'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36','Accept-Encoding':'gzip, deflate, sdch', 'Cookie': '__jdv=122270672|direct|-|none|-|1476333014350; mt_xid=V2_52007VwMRUFxQUl8WTR5sDWIGFlZaUFdGGE0eWhliVxIAQQtTUhdVGVpRNQdAAA1dVVlIeRpdBWAfElNBWFBLH0oSXgRsBhZiX2hSah9LH1wEbgIXYl1eVl4%3D; ipLocation=%u5E7F%u4E1C; ipLoc-djd=19-1607-40152-0; user-key=f20ed039-cf5c-4e40-91a5-a6035a957ac4; cn=0; atw=6881.2490744.12|655.1861125.7; __jda=122270672.1230914856.1474448839.1476333014.1477539207.2; __jdb=122270672.1.1230914856|2.1477539207; __jdc=122270672; __jdu=1230914856' } url='https://diviner.jd.com/diviner?lid=1&p=103003&sku=676676' html=requests.get(url,headers=head) print html.content ``` |