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

标签 python selenium firefox geckodriver selenium-firefoxdriver

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

最佳答案

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

  • 使用 Selenium 时,navigator.webdriver 的值默认设置为 true。此变量将出现在 Chrome 和 Firefox 中。此变量应设置为“未定义”以避免检测。
  • 代理服务器也可用于避免检测。
  • 某些网站能够使用浏览器的状态来确定您是否正在使用 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/

    相关文章:

    firefox - 在 Firefox 扩展中捕获关闭选项卡事件

    firefox - css 中的自定义字体在 firefox 上不起作用

    html - 图片边框在 chrome 和 firefox 中消失,但在 IE 中出现

    python - 稍后如何获取长时间运行的 Google Cloud Speech API 操作的结果?

    python - 在 OS X 菜单栏中更改 Tkinter 应用程序的标题

    python - 网站不允许右键单击,网络抓取不显示正文标签之间的文本

    python - 如何单击父元素

    python - 通过 XPath 获取文本,忽略标记

    python - 将curl get to Rest api转换为python

    python - 使用 Python 测试 Adob​​e Analytics Instrumentation