您好,登錄后才能下訂單哦!
這篇文章主要介紹正則如何給header的冒號兩邊參數添加單引號,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!
正則給header的冒號兩邊參數添加單引號(Python請求用)
直接從瀏覽器Chrome復制header值如下:
Host: kyfw.12306.cn Connection: keep-alive Pragma: no-cache Cache-Control: no-cache Accept: */* X-Requested-With: XMLHttpRequest If-Modified-Since: 0 User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36 Referer: https://kyfw.12306.cn/otn/leftTicket/init?linktypeid=dc&fs=%E4%B8%8A%E6%B5%B7,SHH&ts=%E9%A6%99%E6%B8%AF%E8%A5%BF%E4%B9%9D%E9%BE%99,XJA&date=2019-04-12&flag=N,N,Y Accept-Encoding: gzip, deflate, br Accept-Language: zh-CN,zh;q=0.9 Cookie: JSESSIONID=76B27521A27493046570C27D4EA89116; RAIL_OkLJUJ=FFA0Gp4TGPWRINmcFUWWyIHH0ugtMppg; _jc_save_wfdc_flag=dc; ten_key=ySPk59Ew/hagxMnD31qdYQ64ryEVBMwd; ten_js_key=ySPk59Ew%2FhagxMnD31qdYQ64ryEVBMwd; BIGipServerotn=1123025418.64545.0000; RAIL_EXPIRATION=1555320982648; RAIL_DEVICEID=SandqZ9YRixyZOnJ2ZMUl2iYN8RPrDz8F6WsV6wDEryAZh_41c-qHzPyRmNlJNXpOSoNpmYE3SIpEhKVV06mAxHwB6RWk-l4vxZg0an4qePt-qPsrnaceVrdc7eZzC1dJheS9V9TYLwrGQ_iG85ax_hB8VADhhu3; BIGipServerpool_passport=200081930.50215.0000; route=c5c62a339e7744272a54643b3be5bf64; _jc_save_fromStation=%u4E0A%u6D77%2CSHH; _jc_save_toDate=2019-04-12; BIGipServerportal=2949906698.17695.0000; _jc_save_toStation=%u5357%u5B81%2CNNZ; _jc_save_fromDate=2019-04-30
用正則表達式替換后的如下:(正則替換后再手動去掉最后一行最后一個逗號)
'Host':' kyfw.12306.cn', 'Connection':' keep-alive', 'Pragma':' no-cache', 'Cache-Control':' no-cache', 'Accept':' */*', 'X-Requested-With':' XMLHttpRequest', 'If-Modified-Since':' 0', 'User-Agent':' Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36', 'Referer':' https://kyfw.12306.cn/otn/leftTicket/init?linktypeid=dc&fs=%E4%B8%8A%E6%B5%B7,SHH&ts=%E9%A6%99%E6%B8%AF%E8%A5%BF%E4%B9%9D%E9%BE%99,XJA&date=2019-04-12&flag=N,N,Y', 'Accept-Encoding':' gzip, deflate, br', 'Accept-Language':' zh-CN,zh;q=0.9', 'Cookie':' JSESSIONID=76B27521A27493046570C27D4EA89116; RAIL_OkLJUJ=FFA0Gp4TGPWRINmcFUWWyIHH0ugtMppg; _jc_save_wfdc_flag=dc; ten_key=ySPk59Ew/hagxMnD31qdYQ64ryEVBMwd; ten_js_key=ySPk59Ew%2FhagxMnD31qdYQ64ryEVBMwd; BIGipServerotn=1123025418.64545.0000; RAIL_EXPIRATION=1555320982648; RAIL_DEVICEID=SandqZ9YRixyZOnJ2ZMUl2iYN8RPrDz8F6WsV6wDEryAZh_41c-qHzPyRmNlJNXpOSoNpmYE3SIpEhKVV06mAxHwB6RWk-l4vxZg0an4qePt-qPsrnaceVrdc7eZzC1dJheS9V9TYLwrGQ_iG85ax_hB8VADhhu3; BIGipServerpool_passport=200081930.50215.0000; route=c5c62a339e7744272a54643b3be5bf64; _jc_save_fromStation=%u4E0A%u6D77%2CSHH; _jc_save_toDate=2019-04-12; BIGipServerportal=2949906698.17695.0000; _jc_save_toStation=%u5357%u5B81%2CNNZ; _jc_save_fromDate=2019-04-30'
find匹配:(.*?)\:(.*?)\n
replace替換:'$1':'$2',\n
sublime如下:
匹配效果如下:
以上是“正則如何給header的冒號兩邊參數添加單引號”這篇文章的所有內容,感謝各位的閱讀!希望分享的內容對大家有幫助,更多相關知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。