• 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的请求方式进行请求

  • 相关阅读:
    如何自我介绍可以吸引面试官?
    测试用例有多重要?
    文档测试的要点是什么?
    android应用性能优化技法
    android中的ems的真正含义
    android studio的java代码中,提取普通字符串为常量
    Android配置启动页
    C/C++函数未运行,且显示Process returned -1073741571 (0xC00000FD)
    vue的组件及其使用方法
    Vue关闭ESLint
  • 原文地址:https://www.cnblogs.com/xinzaiyuan/p/13651628.html
Copyright © 2020-2023  润新知