Python 爬蟲出現(ValueError: Invalid header name b':authority')


一,爬取比較有權威的網址

1. 出現

2. 表示在請求頭中有不識別的數據,明顯是無法解析請求頭

3.  這是hppt2的請求,作為RFC 描述,Http 請求頭不能以分號開頭

  安裝hyper進行解析,因為hyper認識這樣的請求頭

pip install hyper

4. 修改代碼

import requests,json
from hyper.contrib import HTTP20Adapter

url = 'https://www.qcc.com/api/bigsearch/judgementList'
headers = {
    ':authority': 'www.a.a',
    ':method': 'POST',
    ':path': '/api/bigsearch/judgementList',
    ':scheme': 'https',
    'accept': 'aa/pa*',
    'accept-encoding': 'ae, br',
    'accept-language': 'a0.9',
    'content-length': '294',
    'content-type': 'at=UTF-8',
    'cookie': 'aa',
    'origin': 'xx',
    'referer': 'xx',
    'sec-fetch-dest': 'x',
    'sec-fetch-mode': 'x',
    'sec-fetch-site': 'x-x',
    'user-agent': 'xxx',
    'x-requested-with': 'xx'
}
payload = {
    "caseName": "",
    "caseNo": "",
    "caseReason": "",
    "content": "",
    "courtName": "",
    "involvedAmtMax": "",
    "involvedAmtMin": "",
    "isExactlySearch": "",
    "judgeDateBegin": "",
    "judgeDateEnd": "",
    "pageSize": "20",
    "party": "xxx",
    "publishDateBegin": "",
    "publishDateEnd": "",
    "searchKey": ""
}
data = json.dumps(payload)


sessions=requests.session()
sessions.mount('https://xxxxx', HTTP20Adapter())
res=sessions.post(url,headers=headers,data=data)
print(res.text)

5. 最后根據method的請求方式進行請求


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM