python - 排除 Firefox Webdriver 选项中的开关

标签 python selenium selenium-firefoxdriver

使用 Selenium 和 python,我可以使用 Chrome webdriver 来完成此操作:

options.add_experimental_option("excludeSwitches", ["enable-automation"])
driver = webdriver.Chrome(options = options)

但我找不到 Firefox 的 webdriver 选项的类似属性。有吗?

最佳答案

Firefox 使用不同的标志。我不确定您的具体目标是什么,但我假设您正在尝试避免某些网站检测到您正在使用 Selenium 。

有多种方法可以避免网站检测到 Selenium 的使用。

1) 使用 Selenium 时,navigator.webdriver 的值默认设置为 true。该变量将出现在 Chrome 和 Firefox 中。该变量应设置为“未定义”以避免检测。

2) 还可以使用代理服务器来避免检测。

3) 一些网站能够使用您的浏览器状态来确定您是否正在使用 Selenium。您可以将 Selenium 设置为使用自定义浏览器配置文件来避免这种情况。

下面的代码使用了所有这三种方法。

profile = webdriver.FirefoxProfile('C:\\Users\\You\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\something.default-release')

PROXY_HOST = "12.12.12.123"
PROXY_PORT = "1234"
profile.set_preference("network.proxy.type", 1)
profile.set_preference("network.proxy.http", PROXY_HOST)
profile.set_preference("network.proxy.http_port", int(PROXY_PORT))
profile.set_preference("dom.webdriver.enabled", False)
profile.set_preference('useAutomationExtension', False)
profile.update_preferences()
desired = DesiredCapabilities.FIREFOX

driver = webdriver.Firefox(firefox_profile=profile, desired_capabilities=desired)

关于python - 排除 Firefox Webdriver 选项中的开关,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57122151/

相关文章:

python - 将字典键转换为具有字典值的变量的最佳方法是什么?

python - 如何检查pandas数据框中是否存在特定条目并添加新条目?

python - django-pipeline - 页面加载真的很慢

Selenium:是否可以将 xpath 与变量连接起来?

Java - Selenium Firefox 驱动程序 - 无法点击模式中的特定按钮

c# - Selenium中使用FireFoxDriver时,如何知道页面Url?

java - Selenium 3.0 Firefx 驱动程序失败,出现 org.openqa.selenium.SessionNotCreatedException : Unable to create new remote session

python - Django:如何在没有此类实例的情况下对另一个类进行反向外键查找?

linux - selenium - webdriver - Firefox 64 位 Linux

python - 在 Selenium WebDriver 中设置加载页面的真正超时?