python - 如何通过 Python 使用 GeckoDriver 和 Firefox 使 Selenium 脚本无法检测到?

标签 python selenium firefox geckodriver selenium-firefoxdriver

有没有办法让你的 Selenium 脚本在 Python 中使用 geckodriver 无法被检测到?

我正在使用 Selenium 进行抓取。我们需要使用任何保护措施以使网站无法检测到 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)

代码运行后,您将能够手动检查 Selenium 运行的浏览器现在是否具有您的 Firefox 历史记录和扩展。您还可以在 devtools 控制台中输入“navigator.webdriver”来检查它是否未定义。

关于python - 如何通过 Python 使用 GeckoDriver 和 Firefox 使 Selenium 脚本无法检测到?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60534531/

相关文章:

python - python中的参数模块?从对象导入函数

python-3.x - Python Selenium,在span中查找文本

node.js - Selenium Node.js转移控制到其他标签

html - 单击文件输入标签的解决方法 (Firefox)

firefox - Shadow DOM v1 CSS polyfill

python - 在训练中使用 One-Hot-Encoding 后获得数据点的正确形状以使用回归模型进行预测

python - 我会遇到 python 的全局解释器锁的问题吗?

python - 为什么我在构建 python 时构建 sqlite3 失败?

java - cucumber JUnit : How to take screenshot when scenario step definitions are spread across classes?

javascript - 为什么这段 javascript 代码不能在 FireFox 中运行