geckodriver、Selenium和 Firefox 版本对应关系

因为限制加载javascript、css、图片,只有图片起作用,别的都没有效果。看到有人说是版本的问题,找了下geckodriver、Selenium和 Firefox 对应关系。
限制加载代码:


from selenium import webdriver

fp = webdriver.FirefoxProfile() 
fp.set_preference("javascript.enabled", 'False') #限制javascript加载
fp.set_preference("permissions.default.image",2) #限制图片加载  
fp.set_preference("permissions.default.stylesheets",2)#限制加载css

driver = webdriver.Firefox(firefox_profile=fp) 
driver.get("http://www.santostang.com/2018/07/04/hello-world/")

查看selenium版本代码:

import selenium 
help(selenium)

selenium VERSION: 3.141.0
geckodriver 0.29.0
Firefox 87.0 (64 位)

geckodriver、Selenium和 Firefox 版本对应关系也查了,好像没问题,但是就是不起作用。

geckodriverSeleniumFirefox minFirefox max
0.29.1≥ 3.11 (3.14 Python)60n/a
0.28.0≥ 3.11 (3.14 Python)60n/a
0.27.0≥ 3.11 (3.14 Python)60n/a
0.26.0≥ 3.11 (3.14 Python)60n/a
0.25.0≥ 3.11 (3.14 Python)57n/a
0.24.0≥ 3.11 (3.14 Python)5779
0.23.0≥ 3.11 (3.14 Python)5779
0.22.0≥ 3.11 (3.14 Python)5779
0.21.0≥ 3.11 (3.14 Python)5779
0.20.1≥ 3.55562
0.20.0≥ 3.55562
0.19.1≥ 3.55562
0.19.0≥ 3.55562
0.18.0≥ 3.45362
0.17.0≥ 3.45262

版本对应关系详见:https://firefox-source-docs.mozilla.org/testing/geckodriver/Support.html

  • 10
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
GeckoDriver 是一个用于驱动 Firefox 浏览器的 WebDriver。在 Java 开发中,你可以使用 Selenium WebDriver 来控制浏览器的行为。 下面是一个简单的 GeckoDriver Java 开发教程: 第一步:安装 Firefox 浏览器和 GeckoDriver 1. 下载并安装最新版本Firefox 浏览器:https://www.mozilla.org/firefox/ 2. 下载 GeckoDriver,它与你所使用的 Firefox 版本对应:https://github.com/mozilla/geckodriver/releases 第二步:配置 Java 项目 1. 创建一个 Maven 项目或者添加 Selenium WebDriver 依赖到你的项目中。在 pom.xml 文件中添加以下依赖: ```xml <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>{最新版本号}</version> </dependency> ``` 2. 导入必要的类: ```java import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxOptions; ``` 第三步:编写代码 1. 设置 GeckoDriver 的路径: ```java System.setProperty("webdriver.gecko.driver", "/path/to/geckodriver"); ``` 将 "/path/to/geckodriver" 替换为你下载的 GeckoDriver 的实际路径。 2. 创建 FirefoxOptions 对象,并禁用日志输出: ```java FirefoxOptions options = new FirefoxOptions(); options.setLogLevel(FirefoxDriverLogLevel.ERROR); ``` 3. 初始化 WebDriver 对象,并启动 Firefox 浏览器: ```java WebDriver driver = new FirefoxDriver(options); ``` 4. 开始使用 WebDriver 进行各种操作,例如打开网页、查找元素、执行操作等: ```java driver.get("https://www.example.com"); WebElement element = driver.findElement(By.id("elementId")); element.click(); ``` 5. 最后,记得关闭 WebDriver 和 Firefox 浏览器: ```java driver.quit(); ``` 这就是一个简单的 GeckoDriver Java 开发教程。希望对你有所帮助!如果还有其他问题,请随时提问。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值