Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何通过Python使用GeckoDriver和Firefox使Selenium脚本不可检测?_Python_Selenium_Firefox_Geckodriver_Selenium Firefoxdriver - Fatal编程技术网

如何通过Python使用GeckoDriver和Firefox使Selenium脚本不可检测?

如何通过Python使用GeckoDriver和Firefox使Selenium脚本不可检测?,python,selenium,firefox,geckodriver,selenium-firefoxdriver,Python,Selenium,Firefox,Geckodriver,Selenium Firefoxdriver,有没有一种方法可以使用geckodriver使您的Selenium脚本在Python中不可检测 我用硒来刮东西。我们需要使用哪些保护措施才能使网站检测不到硒?检测到硒驱动的Firefox/GeckoDriver并不取决于任何特定的GeckoDriver或Firefox版本。网站本身可以检测网络流量,并可以将浏览器客户端(即Web浏览器)识别为受控制的WebDriver 根据最新编辑草稿中的文档,webdriver active标志最初设置为false,当用户代理处于远程控制下,即通过控制时,该标

有没有一种方法可以使用geckodriver使您的Selenium脚本在Python中不可检测

我用硒来刮东西。我们需要使用哪些保护措施才能使网站检测不到硒?

检测到硒驱动的Firefox/GeckoDriver并不取决于任何特定的GeckoDriver或Firefox版本。网站本身可以检测网络流量,并可以将浏览器客户端(即Web浏览器)识别为受控制的WebDriver

根据最新编辑草稿中的文档,
webdriver active
标志最初设置为false,当用户代理处于远程控制下,即通过控制时,该标志设置为true

现在,
导航器自动信息
界面不应暴露在
WorkerNavigator

所以

作为

navigator.webdriver
    Defines a standard way for co-operating user agents to inform the document that it is controlled by WebDriver, for example so that alternate code paths can be triggered during automation.
因此,底线是:

硒识别自身


但是,一些通用的方法可以避免在web抓取时被检测到,如下所示:

  • 网站可以确定脚本/程序的首要属性是通过您的监视器大小。因此,建议不要使用常规方法
  • 如果需要向一个网站发送多个请求,则需要不断更改每个请求的用户代理。在这里,您可以找到有关的详细讨论
  • 要模拟类似人类的行为,您可能需要将脚本执行速度减慢,甚至超过并导致
    time.sleep(秒)
    。在这里,您可以找到有关的详细讨论
    • 检测到selenium驱动的Firefox/GeckoDriver并不取决于任何特定的GeckoDriver或Firefox版本。网站本身可以检测网络流量,并可以将浏览器客户端(即Web浏览器)识别为受控制的WebDriver

      根据最新编辑草稿中的文档,
      webdriver active
      标志最初设置为false,当用户代理处于远程控制下,即通过控制时,该标志设置为true

      现在,
      导航器自动信息
      界面不应暴露在
      WorkerNavigator

      所以

      作为

      navigator.webdriver
          Defines a standard way for co-operating user agents to inform the document that it is controlled by WebDriver, for example so that alternate code paths can be triggered during automation.
      
      因此,底线是:

      硒识别自身


      但是,一些通用的方法可以避免在web抓取时被检测到,如下所示:

      • 网站可以确定脚本/程序的首要属性是通过您的监视器大小。因此,建议不要使用常规方法
      • 如果需要向一个网站发送多个请求,则需要不断更改每个请求的用户代理。在这里,您可以找到有关的详细讨论
      • 要模拟类似人类的行为,您可能需要将脚本执行速度减慢,甚至超过并导致
        time.sleep(秒)
        。在这里,您可以找到有关的详细讨论

      有不同的方法避免网站检测到硒的使用

    • 使用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”以检查它是否未定义。

      有不同的方法避免网站检测到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”以检查它是否未定义。

      什么意思?你从网页上得到了阻止吗?@HjSin是的,网站阻止了我,并在1到2分钟后一次又一次地给我验证码,他给了我验证码和other@HjSin我想这个网站正在检测我,你在用什么网站?如果一个网站被屏蔽,那意味着它不允许机器人。意思是?你从网页上得到了阻止吗?@HjSin是的,网站阻止了我,并在1到2分钟后一次又一次地给我验证码,他给了我验证码和other@HjSin我认为该网站正在检测我你在使用哪个网站?如果网站被阻止,这意味着它不允许使用机器人。这是迄今为止唯一一个对我有效的解决方案。真的很感谢分享!我应该用“DesiredCapabilities”试试什么样的例子?这个解决方案对我来说很有效,即使没有代理。唯一的一个问题是开封时冰箱被悬挂