python发送post请求,参数填完了加载不出网页是为什么

img


正常还说填完了参数,就应该可以了不知道为什么返回的302


 url = 'https://www.xyhn.gov.cn/creditdatas/cms/getSubjectDetailByTableName'
        params = {
                'pageSize': '10',
                'page': '1',
                'tableId': '02300C751645417CA3D19D1FC00A15B3',
                'category': 'credit_xyzx_fr_xzcf_new',
                'flag':'1'
            }
        res = requests.post(url=url,headers=self.headers,data=params)
        page_text = res.text
        print(page_text)

img

你把那个请求头全部加上试试就可以了。

import requests
import demjson

url = 'https://www.xyhn.gov.cn/creditdatas/cms/getSubjectDetailByTableName'
data = {
    'pageSize': 10,
    'tableId': '02300C751645417CA3D19D1FC00A15B3',
    'category': 'credit_xyzx_fr_xzcf_new',
    'flag': 1
}
headers = {"Accept": "application/json, text/javascript, */*; q=0.01",
           "Accept-Encoding": "gzip, deflate, br",
           "Accept-Language": "zh-CN,zh;q=0.9",
           "Connection": "keep-alive",
           "Content-Length": "92",
           "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
           "Cookie": "say=xyhn223.155.80.11; JSESSIONID=3236326385C740982C2D79BD27625291; sid=0c5dfd3c-d505-4506-a9d9-1511d8329d79; nS_wcI_5f=G36gI37arWzQoLXGytgXtUYLlTpBZfj0uDW+Gg==; say=xyhn223.155.80.11",
           "Host": "www.xyhn.gov.cn",
           "Origin": "https://www.xyhn.gov.cn",
           "Referer": "https://www.xyhn.gov.cn/ca/20160419000001.htm",
           # "sec-ch-ua": " Not;A Brand;v=99, Google Chrome;v=97, Chromium;v=97",
           "sec-ch-ua-mobile": "?0",
           "sec-ch-ua-platform": "Windows",
           "Sec-Fetch-Dest": "empty",
           "Sec-Fetch-Mode": "cors",
           "Sec-Fetch-Site": "same-origin",
           "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36",
           "X-Requested-With": "XMLHttpRequest"}
rsp = requests.post(url=url, data=data, headers=headers)
list2 = demjson.decode(rsp.text)['data'][0]['catalogSearch']['list']
for l in list2:
    print(l)

应该是你爬取的网页有反爬功能,尝试换种方式获取

网页是https://www.xyhn.gov.cn/ca/20160419000001.htm
我数据来源的地方点进去就是302,很好奇数据是怎么来的

302是重定向,什么是重定向啊?就是地址A跳转到地址B啦。