Selenium Wire webdriver无法访问网站

0 投票
1 回答
53 浏览
提问于 2025-04-12 02:39

我正在使用Python和Selenium(selenium-wire)来自动控制浏览器,访问两个网站。大部分网站,比如:https://www.google.com
https://platform.cmcmarkets.com/
,在使用selenium-wire的chromedriver时都能正常访问。

但是,当我访问这个网站:https://app.plus500.com/时,浏览器却显示了一个Chrome错误页面,上面写着:

This site can’t be reached  
The web page at https://app.plus500.com/ might be temporarily down or it may have moved permanently to a new web address.
ERR_HTTP2_PROTOCOL_ERROR

selenium-wire是一个Python模块,它扩展了selenium的功能,可以捕获请求和响应。使用普通的selenium webdriver也能访问这个网站,所以问题似乎出在使用的selenium-wire包上。

将selenium-wire发出的根证书导入Chrome后,就可以在浏览HTTPS网站时避免出现“您的连接不是私密连接”的屏幕。

奇怪的是,虽然google.com(和其他网站)的证书查看器显示了Selenium Wire CA:

Common Name (CN)    www.google.com
Organisation (O)    <Not part of certificate>
Organisational Unit (OU)    <Not part of certificate>
Common Name (CN)    Selenium Wire CA
Organisation (O)    <Not part of certificate>
Organisational Unit (OU)    <Not part of certificate>

但是app.plus500.com却没有:

Common Name (CN)    *.plus500.com
Organisation (O)    Edgio, Inc.
Organisational Unit (OU)    <Not part of certificate>
Common Name (CN)    DigiCert Global G2 TLS RSA SHA256 2020 CA1
Organisation (O)    DigiCert Inc
Organisational Unit (OU)    <Not part of certificate>

plus500.com网站随后报告我处于离线状态,可能是因为某些应用资源加载失败。不过它确实报告证书是有效的,所以这似乎不是问题所在。

我还尝试在selenium-wire选项中切换mitmproxy后端,但也没有成功。

对服务器在443端口的抓包显示,连接失败的序列与服务器发出的额外TCP RST有关,但我无法从中解读出更多信息。

如果有人能帮忙诊断这个问题,那就太好了!

1 个回答

1

根据seleniumwire的作者的建议,关闭seleniumwire_options中的mitm_http2选项,结果对我来说并没有效果:

seleniumwire_options = {
    'mitm_http2': False,
}

我把这个放在这里是因为其他用户在其他网站上使用这个方法成功了。

最后,我选择的解决办法是关闭我使用的chromedriver中的HTTP2功能:

chrome_options.add_argument('--disable-http2')

撰写回答