解决了谢谢各位的帮助, 主要参考的是 @
Cleric 的思路, 我用了 pychrome
基本代码在这里比较粗糙
```
import pychrome
from urllib.parse import urlparse
import subprocess, signal
import os
import time
def killprocess(pname):
p = subprocess.Popen(['ps', '-A'], stdout=subprocess.PIPE)
out, err = p.communicate()
for line in out.splitlines():
pinfo = line.decode().lower()
if pname in pinfo:
pid = int(line.split(None, 1)[0])
os.kill(pid, signal.SIGKILL)
header = dict()
url = "
https://www.dogedoge.com"
if not url.endswith('/'):
url += '/'
domain = urlparse(url).netloc
killprocess('chrome')
cmd = 'google-chrome-stable --remote-debugging-port=9222'
p = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE)
time.sleep(3)
# 创建一个浏览器实例
browser = pychrome.Browser(url="http://127.0.0.1:9222")
# 新建一个页签
tab = browser.new_tab()
# 需要注册的回调函数
def request_will_be_sent(**kwargs):
if url == kwargs.get('request').get('url'):
header = kwargs.get('request').get('headers')
return
tab.Network.requestWillBeSent = request_will_be_sent
# 开始接收消息, requestWillBeSent 事件发生时被注册的回调函数也可以执行
tab.start()
# 调用方法
tab.Network.enable()
# 调用方法并设置超时时间
tab.Page.navigate(url=url, _timeout=5)
input()
# 等待页面加载
tab.wait(5)
# 停止处理事件, 停止从 chrome 接收消息
tab.stop()
# 关闭页签
browser.close_tab(tab)
```