有没有办法使用 使您的 Selenium 脚本在 Python 中无法检测到geckodriver ?
我正在使用 Selenium 进行抓取。我们是否需要使用任何保护措施使网站无法检测到 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/58873022/