Selenium与Firefox不兼容.浏览器变为红色并关闭



在其他地方没有看到类似的问题,但当我运行代码时会发生这种情况。我想要的网页打开,但在我的浏览器变红并关闭页面后立即打开。这只发生在webdriver和selenium中,而不是请求。Geckodriver是Firefox使用的。非常确定Gecko安装正确,它在我的PATH中。之前它什么都没做。所以我不认为这是当前的问题。再次在谷歌上搜索,我没有看到其他人的浏览器变红。我想知道这是否只是我需要更改的文件名,但我知道那会是什么文件。

这是我的代码:''

from selenium import webdriver
from selenium.webdriver.common import keys
import requests
import time
from bs4 import BeautifulSoup as bs
import re


driver = webdriver.Firefox()
r = driver.get('https://docs.pytest.org/en/stable/')
soup = bs(r, 'html').content
print(r.content)

''

确保您已经下载了最新的gekodriver:

https://github.com/mozilla/geckodriver/releases

并将其作为传递给驾驶员

webdriver.Firefox(executable_path="pathtogeko/gekodriver.exe")

这将确保您使用正确的gekodriver。

最新更新