{"id":176624,"date":"2020-10-10T09:08:22","date_gmt":"2020-10-10T01:08:22","guid":{"rendered":"http:\/\/4563.org\/?p=176624"},"modified":"2020-10-10T09:08:22","modified_gmt":"2020-10-10T01:08:22","slug":"chrome-%e5%a6%82%e4%bd%95%e5%bf%ab%e9%80%9f%e8%8e%b7%e5%8f%96-request-header%ef%bc%9f","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=176624","title":{"rendered":"Chrome \u5982\u4f55\u5feb\u901f\u83b7\u53d6 request header\uff1f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  Chrome \u5982\u4f55\u5feb\u901f\u83b7\u53d6 request header\uff1f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : woshichuanqilz <\/span>  <span><i><\/i> 7<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u4e00\u822c\u7684\u505a\u6cd5\u5c31\u662f f12 \u6253\u5f00 dev tool \u7136\u540e\u590d\u5236\u7c98\u8d34\uff0c<\/p>\n<p>\u4f46\u662f\u73b0\u5728\u60f3\u7528\u7a0b\u5e8f\u81ea\u52a8\u5316\u7684\u5b9e\u73b0\u8fd9\u4e2a\u529f\u80fd<\/p>\n<p>\u6211\u8fd9\u8fb9\u7528\u4e86 mitmproxy \u6bd4\u8f83\u5361\u3002<\/p>\n<p>\u7136\u540e\u60f3\u5230\u4e86 tampermonkey\uff0c \u4e0d\u592a\u719f\u6089 js \u6ca1\u6709\u627e\u5230\u529e\u6cd5\uff0c \u8fd9\u91cc\u8bf7\u95ee\u4e00\u4e0b\u5982\u4f55\u80fd\u5b9e\u73b0\u8fd9\u4e2a\u529f\u80fd\u3002 \u901a\u8fc7\u540e\u53f0\u7684\u7a0b\u5e8f\u81ea\u52a8\u5316\u7684\u83b7\u53d6 request header<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>10<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"3895000\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : locoz <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4ee3\u7406\u662f\u6700\u597d\u7684\u529e\u6cd5\u4e86\u2026                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3895001\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ClericPy <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             &#8220;`<br \/>import asyncio<br \/>from ichrome import AsyncChromeDaemon, AsyncTab<\/p>\n<p>async def show_headers(tab: AsyncTab):<br \/> await tab.wait_response(filter_function=lambda r: &#8216;httpbin.org\/headers&#8217; in<br \/> r[&#8216;params&#8217;][&#8216;response&#8217;][&#8216;url&#8217;],<br \/>  callback_function=lambda r: print(<br \/> r[&#8216;params&#8217;][&#8216;response&#8217;][&#8216;headers&#8217;], &#8216;n&#8217;, r[<br \/> &#8216;params&#8217;][&#8216;response&#8217;][&#8216;requestHeaders&#8217;]))<br \/> # await tab.wait_request(lambda r: print(r))<\/p>\n<p>async def main():<br \/> async with AsyncChromeDaemon() as cd:<br \/> async with cd.connect_tab() as tab:<br \/> task = asyncio.create_task(show_headers(tab))<br \/> await tab.goto(&#8216;https:\/\/httpbin.org\/headers&#8217;)<br \/> # print(await tab.html)<br \/> await task<\/p>\n<p>if __name__ == &#8220;__main__&#8221;:<br \/> asyncio.run(main())<\/p>\n<p>&#8220;`                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3895002\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : yucongo <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u81ea\u5df1\u89e3\u6790\u89e3\u5bc6 chrome \u7684 sqlite3 \u683c\u5f0f cookies \u5e93\uff08\u53ef\u80fd\u6bd4\u60f3\u8c61\u7684\u7a0d\u5fae\u96be\u4e00\u70b9\uff09\u6216\u662f\u7528 browser-cookie3 https:\/\/pypi.org\/project\/browser-cookie3\/                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3895003\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : crab <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             https:\/\/chromedevtools.github.io\/devtools-protocol\/                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3895004\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : mengyx <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6211\u7528\u505a\u8fc7\u4e00\u4e2a Golang \u7684 MITM Proxy \u3002\u6027\u80fd\u8fd8\u884c\uff0c\u5916\u5305\u7684\u9879\u76ee\u4e2d\u5b9e\u9645\u9a8c\u8bc1\u8fc7\uff0c\u9700\u8981\u7684\u8bdd\u53ef\u4ee5\u627e\u6211                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3895005\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : mengyx <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6216\u8005 Chrome \u7684 Devtools \u4e5f\u6709\u76f8\u5e94 Api\uff0chttps:\/\/chromedevtools.github.io\/devtools-protocol\/                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3895006\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ClericPy <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             V2 \u541e\u6211\u7a7a\u683c&#8230;?<\/p>\n<p>https:\/\/paste.ubuntu.com\/p\/QrDmcGwxvS\/<\/p>\n<p>\u52a0\u4e0a Headless \u548c\u7981\u7528\u56fe\u7247, \u4e5f\u53ef\u4ee5\u5c4f\u853d css \u548c mp4 \u6ca1\u653e\u4e0a, \u51b7\u542f\u52a8 3 \u79d2, \u8fde\u63a5\u5df2\u7ecf\u542f\u52a8\u7684 tab \u5927\u6982 1 \u79d2(\u57fa\u672c\u5c31\u662f\u82b1\u5728\u4e0b\u8f7d), \u540c\u57df\u540d\u5e76\u53d1\u88ab Chrome \u9650\u5236\u5728 6 \u4ee5\u5185, \u6240\u4ee5\u6ca1\u5199\u5e76\u53d1\u7684                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3895007\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : kajweb <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6211\u6700\u8fd1\u51c6\u5907\u5f00\u6e90\u7684 stop-debugger \u60a8\u53ef\u4ee5\u5173\u6ce8\u4e00\u4e0b\uff0c\u57fa\u4e8e node \u5c4f\u853d\u6d4f\u89c8\u5668\u8c03\u8bd5 debugger \u3002<br \/>\u91cc\u9762\u7684 proxy-serve \u6a21\u5757\u53ef\u4ee5\u6ee1\u8db3\u60a8\u7684\u8981\u6c42\u3002<br \/>\u57fa\u672c\u539f\u7406\u662f\u4f7f\u7528 net \u6a21\u5757\u83b7\u5f97\u8bf7\u6c42\u5e76\u8fdb\u884c\u4ee3\u7406\u3002<\/p>\n<p>https:\/\/github.com\/kajweb\/stop-debugger                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3895008\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : kajweb <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6d4f\u89c8\u5668\u62d3\u5c55\u53ef\u4ee5\u53c2\u8003 XSwitch \u7684\u6e90\u7801                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3895009\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : woshichuanqilz <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u89e3\u51b3\u4e86\u8c22\u8c22\u5404\u4f4d\u7684\u5e2e\u52a9\uff0c \u4e3b\u8981\u53c2\u8003\u7684\u662f @Cleric \u7684\u601d\u8def\uff0c \u6211\u7528\u4e86 pychrome<\/p>\n<p>\u57fa\u672c\u4ee3\u7801\u5728\u8fd9\u91cc\u6bd4\u8f83\u7c97\u7cd9<\/p>\n<p>&#8220;`<br \/>import pychrome<br \/>from urllib.parse import urlparse<br \/>import subprocess, signal<br \/>import os<br \/>import time<\/p>\n<p>def killprocess(pname):<br \/> p = subprocess.Popen([&#8216;ps&#8217;, &#8216;-A&#8217;], stdout=subprocess.PIPE)<br \/> out, err = p.communicate()<br \/> for line in out.splitlines():<br \/> pinfo = line.decode().lower()<br \/> if pname in pinfo:<br \/> pid = int(line.split(None, 1)[0])<br \/> os.kill(pid, signal.SIGKILL)<\/p>\n<p>header = dict()<br \/>url = &#8220;https:\/\/www.dogedoge.com&#8221;<br \/>if not url.endswith(&#8216;\/&#8217;):<br \/> url += &#8216;\/&#8217;<br \/>domain = urlparse(url).netloc<br \/>killprocess(&#8216;chrome&#8217;)<br \/>cmd = &#8216;google-chrome-stable &#8211;remote-debugging-port=9222&#8217;<br \/>p = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE)<br \/>time.sleep(3)<\/p>\n<p># \u521b\u5efa\u4e00\u4e2a\u6d4f\u89c8\u5668\u5b9e\u4f8b<br \/>browser = pychrome.Browser(url=&#8221;http:\/\/127.0.0.1:9222&#8243;)<\/p>\n<p># \u65b0\u5efa\u4e00\u4e2a\u9875\u7b7e<br \/>tab = browser.new_tab()<\/p>\n<p># \u9700\u8981\u6ce8\u518c\u7684\u56de\u8c03\u51fd\u6570<br \/>def request_will_be_sent(**kwargs):<br \/> if url == kwargs.get(&#8216;request&#8217;).get(&#8216;url&#8217;):<br \/> header = kwargs.get(&#8216;request&#8217;).get(&#8216;headers&#8217;)<br \/> return<\/p>\n<p>tab.Network.requestWillBeSent = request_will_be_sent<\/p>\n<p># \u5f00\u59cb\u63a5\u6536\u6d88\u606f, requestWillBeSent \u4e8b\u4ef6\u53d1\u751f\u65f6\u88ab\u6ce8\u518c\u7684\u56de\u8c03\u51fd\u6570\u4e5f\u53ef\u4ee5\u6267\u884c<br \/>tab.start()<\/p>\n<p># \u8c03\u7528\u65b9\u6cd5<br \/>tab.Network.enable()<\/p>\n<p># \u8c03\u7528\u65b9\u6cd5\u5e76\u8bbe\u7f6e\u8d85\u65f6\u65f6\u95f4<br \/>tab.Page.navigate(url=url, _timeout=5)<br \/>input()<br \/># \u7b49\u5f85\u9875\u9762\u52a0\u8f7d<br \/>tab.wait(5)<\/p>\n<p># \u505c\u6b62\u5904\u7406\u4e8b\u4ef6, \u505c\u6b62\u4ece chrome \u63a5\u6536\u6d88\u606f<br \/>tab.stop()<\/p>\n<p># \u5173\u95ed\u9875\u7b7e<br \/>browser.close_tab(tab)<\/p>\n<p>&#8220;`                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>Chrome \u5982\u4f55\u5feb\u901f\u83b7\u53d6 req&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/176624"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=176624"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/176624\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=176624"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=176624"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=176624"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}