美文网首页
Pycharm正则格式化请求头

Pycharm正则格式化请求头

作者: 艾胖胖胖 | 来源:发表于2018-10-25 16:02 被阅读0次

    从浏览器拷贝出来请求头后, 需要手动的一个个加引号和逗号。现在我们利用Pycharm来进行批量替换。

    • 浏览器下拷贝出来的请求头
    //请求头
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
    Accept-Encoding: gzip, deflate, br
    Accept-Language: zh-CN,zh;q=0.9
    Cache-Control: no-cache
    Connection: keep-alive
    Cookie: read_mode=day; default_font=font2; locale=zh-CN; remember_user_token=W1231sxMzYwNzkwMF0sIiQyYSQxMSRnNVl5MWpmZ0JINXJVazFreXlzQ0V1IiwiMTU0MDI1NTAzNS4xMDE5NDAyIl0%3D--10326e210f857747d9a7c9ace127cab6cdf8d947e; Hm_lvt_0c0e9d9b1e7d617b3e6842e85b9fb068=1540276756,1540284104,1540301802,1540371744; _m7e_session=dbf3985c991afa4c90bb79228626ed6e; Hm_lpvt_0c0e9d9b1e7d617b3e6842e85b9fb068=1540453366; sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%221663393b621590-01c145ebcced4d-8383268-2073600-1663393b62272c%22%2C%22%24device_id%22%3A%221663393b621590-01c145ebcced4d-8383268-2073600-1663393b62272c%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E8%87%AA%E7%84%B6%E6%90%9C%E7%B4%A2%E6%B5%81%E9%87%8F%22%2C%22%24latest_referrer%22%3A%22https%3A%2F%2Fwww.baidu.com%2Flink%22%2C%22%24latest_referrer_host%22%3A%22www.baidu.com%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC%22%2C%22%24latest_utm_source%22%3A%22desktop%22%2C%22%24latest_utm_medium%22%3A%22not-signed-in-like-button%22%2C%22%24latest_utm_campaign%22%3A%22maleskine%22%2C%22%24latest_utm_content%22%3A%22note%22%7D%2C%22first_id%22%3A%22%22%7D
    Host: www.jianshu.com
    Pragma: no-cache
    Referer: https://www.jianshu.com/c/068668542235
    Upgrade-Insecure-Requests: 1
    User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36
    
    
    • 使用Pycharm的替换
    勾选Regex使用正则来对数据进行匹配批量修改
    //利用冒号做分割
    正则表达式:(.*?): ?(.*)
    //给冒号两边的数据都加上单引号, 并且在末尾增加逗号
    需要替换成:'$1':'$2',    #主要要包含逗号
    
    
    • 替换之前


      正则匹配.png
    • 替换以后


      image.png

    相关文章

      网友评论

          本文标题:Pycharm正则格式化请求头

          本文链接:https://www.haomeiwen.com/subject/yuhctqtx.html