zoukankan      html  css  js  c++  java
  • 请求头headers

    方便填写请求头,不用操作每个参数,这里介绍一个库 copyheaders

    安装 pip install copyheaders

    例子

    import requests
    from copyheaders import headers_raw_to_dict
    
    r_h=b'''
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
    Accept-Encoding: gzip, deflate, br
    Accept-Language: zh-CN,zh;q=0.9
    Cache-Control: no-cache
    Connection: keep-alive
    Cookie: BAIDUID=89CEA91EFA6933192A1ADA8096CAAE4F:FG=1; cflag=13%3A3; pgv_pvi=1338484736; BDUSS=pVRHpUMXJJWE1zRWNwTlpuSVR0dFlCV0M3N1p4OHdhUHlLR3NxOFY1QkNva05lSVFBQUFBJCQAAAAAAAAAAAEAAABU6WbpaWhhbmtsZW8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEIVHF5CFRxeeG; MCITY=-340%3A; BIDUPSID=89CEA91EFA6933192A1ADA8096CAAE4F; PSTM=1579079326; BD_HOME=1; H_PS_PSSID=1446_21090_26350; BD_UPN=12314753
    Host: www.baidu.com
    Pragma: no-cache
    Sec-Fetch-Mode: navigate
    Sec-Fetch-Site: none
    Sec-Fetch-User: ?1
    Upgrade-Insecure-Requests: 1
    User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36
    '''
    headers = headers_raw_to_dict(r_h)
    response=requests.get(''https://www.baidu.com/'',headers=headers).content.decode()
    print(response)
    
  • 相关阅读:
    处理emacs-org模式TODO的一个脚本
    MYSQL 数据类型
    Redis命令学习-Transaction(事务)
    成都青羊考场科目二考试分享
    地图入门_坐标系统
    microsoft SQL server,错误2
    搭建个人博客 方式2 使用jekyll
    WIN10 10招
    java正則表達式总结
    图解hdu5301Buildings
  • 原文地址:https://www.cnblogs.com/hankleo/p/12197793.html
Copyright © 2011-2022 走看看