zoukankan      html  css  js  c++  java
  • 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的请求方式进行请求

  • 相关阅读:
    python学习笔记(4)装饰器
    python学习笔记(3)函数
    python学习笔记(2)集合
    python学习笔记(1)字典
    nginx.conf文件内容详解
    关于斐波拉契数列引出的迭代器生成器的一点讨论
    MAC电脑运行python并发编程遇到的问题
    docker 11 :私有仓库搭建
    docker 10 :docker单机网络模式
    【转】C#环形队列
  • 原文地址:https://www.cnblogs.com/xinzaiyuan/p/13651628.html
Copyright © 2011-2022 走看看