求助:python post请求访问不到数据

一也
  • 46

本人想获取该网址中的:[http://guba.eastmoney.com/lis...]人气排名的那个排名,现在已知这是一个XHR,并且也可以看到hearder,也用post传了参数但是获取不到内容,请求帮忙。 具体请求原始参数如下图:image.png
image.png
我的代码是下图,但是获取不到数据:image.png

文本代码如下:

import requests
    url ='http://guba.eastmoney.com/interface/GetData.aspx'
    form_data={'param':'code%3D300729&path=webarticlelist%2Fapi%2Fguba%2Fgubainfo&env=2'}
    header ={
            "accept": "application/json, text/javascript, */*; q=0.01",
            "accept-language": "zh-CN,zh;q=0.9",
            "content-type": "application/x-www-form-urlencoded; charset=UTF-8",
            "x-requested-with": "XMLHttpRequest",
            "referrer": "http://guba.eastmoney.com/list,300729.html",
            "cookie": "waptgshowtime=202091; cowCookie=true; intellpositionL=1010.67px; _qddaz=QD.a790ti.dylgd2.kek1yxrl; pgv_pvi=3795830784; intellpositionT=455px; em_hq_fls=js; em-quote-version=topspeed; HAList=a-sz-300880-N%u8FE6%u5357%2Ca-sh-600000-%u6D66%u53D1%u94F6%u884C; emshistory=%5B%22000002%22%2C%220000001%22%2C%22000001%22%5D; st_si=25560830207677; st_asi=delete; qgqp_b_id=a625961c5087e2fa2d1ca96b4d1233bb; st_pvi=18626401521226; st_sp=2020-09-01%2022%3A26%3A49; st_inirUrl=https%3A%2F%2Fwww.baidu.com%2Flink; st_sn=8; st_psi=20200902172011526-0-7910025548",
            'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.135 Safari/537.36"
            ,"Origin": "http://guba.eastmoney.com"
            ,"Connection": "keep-alive"
    }
    response = requests.post(url, data=form_data, headers=header)
    print(response.text)

请求大神帮忙看下

回复
阅读 849
1 个回答

你应该是没传host

import requests
url ='http://guba.eastmoney.com/interface/GetData.aspx'
form_data={'param':'code=300729','path':'webarticlelist/api/guba/gubainfo','env':2}
headers = {
    'Accept': 'application/json, text/javascript, */*; q=0.01',
    'Accept-Encoding': 'gzip, deflate',
    'Accept-Language': 'zh-CN,zh;q=0.9',
    'Connection': 'keep-alive',
    'Content-Length': '69',
    'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
    'Cookie': 'st_si=80426273055812; st_asi=delete; qgqp_b_id=034c32543e0665e60a6abe212df2b999; st_pvi=75577916022409; st_sp=2020-09-02%2019%3A04%3A07; st_inirUrl=http%3A%2F%2Fguba.eastmoney.com%2Flist%2C300729.html; st_sn=3; st_psi=20200902190407540-117001301474-0318188031',
    'Host': 'guba.eastmoney.com',
    'Origin': 'http://guba.eastmoney.com',
    'Referer': 'http://guba.eastmoney.com/list,300729.html',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36',
    'X-Requested-With': 'XMLHttpRequest'
}
response = requests.post(url, data=form_data, headers=headers).text
print(response)
# {"bar_rank":0,"stockbar_fans_count":0,"popular_rank":164,"popular_change":-7,"rc":1,"me":"操作成功","time":"0001-01-01T00:00:00"}
你知道吗?

宣传栏