Python 使用硒刮削bet365.com时的最后一个问题

Python 使用硒刮削bet365.com时的最后一个问题,python,selenium,selenium-webdriver,web-scraping,selenium-chromedriver,Python,Selenium,Selenium Webdriver,Web Scraping,Selenium Chromedriver,在社区中查找信息后,我在一篇帖子中看到,下一个代码直到几天前仍然有效: from selenium import webdriver options = webdriver.ChromeOptions() options.add_argument("window-size=1920,1080") options.add_experimental_option("excludeSwitches", ["enable-automation"

在社区中查找信息后,我在一篇帖子中看到,下一个代码直到几天前仍然有效:

from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument("window-size=1920,1080")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
browser=webdriver.Chrome(options=options,executable_path=r"chromedriver.exe")

browser.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
                                  "source": """
                                    Object.defineProperty(navigator, 'webdriver', {
                                      get: () => undefined
                                    })
                                  """
                                })
browser.execute_cdp_cmd('Network.setUserAgentOverride', 
                                    {"userAgent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4240.198 Safari/537.36'})
browser.get('https://www.bet365.com')
在此之后,下一个解决方案起到了作用: 使用记事本++打开文件chromedriver.exe,搜索“cdc_uu”并将其替换为“xyz_u”,然后保存该文件。并将此行添加到chromedriver:options.add_参数('--disable blink features=AutomationControlled')的选项中

我不知道为什么这对我不起作用。我正在使用Chrome 88.0.4324.146和chromedriver版本88.0.4324.96,并执行以下代码:

from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument("window-size=1920,1080")
options.add_argument('--disable-blink-features=AutomationControlled')
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
options.add_argument('--disable-blink-features=AutomationControlled')
browser=webdriver.Chrome(options=options,executable_path=r"chromedriver.exe")

browser.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
                                  "source": """
                                    Object.defineProperty(navigator, 'webdriver', {
                                      get: () => undefined
                                    })
                                  """
                                })
browser.execute_cdp_cmd('Network.setUserAgentOverride', 
                                    {"userAgent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4240.198 Safari/537.36'})
browser.get('https://www.bet365.com')
但是在执行之后,页面在加载时会被卡住,直到崩溃

import subprocess
#other imports

subprocess.Popen(
   '"C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe" --remote-debugging-port=9222', shell=True)
   
options = webdriver.ChromeOptions()
options.add_experimental_option("debuggerAddress", "127.0.0.1:9222")

driver = webdriver.Chrome(options=options)
driver.maximize_window()
driver.get('https://www.bet365.com')
该站点似乎检测到了自动化的一些方法,解决方法是使用调试地址打开chrome,然后使用上述代码将selenium连接到该站点。根据您的环境更改chrome.exe
注意:请确保在运行此脚本之前关闭所有chrome浏览器

我想我明白了,但我有一些问题。你用调试地址打开chrome是什么意思,你能解释一下怎么做吗?我想你的意思是,一旦你“使用调试地址”打开chrome,确保在运行上面的代码之前唯一打开的chrome选项卡是该选项卡,不是吗?@scraper只需按原样运行代码,关闭所有chrome并运行代码。这将启动chrome,并打开端口9222进行调试。我们可以通过selenium chromedriver选项连接到此地址。添加“debuggerAddress”,“127.0.0.1:9222”选项(“debuggerAddress”,“127.0.0.1:9222”),我想知道bet365将更改多少次代码以获得多少个机器人。@PDHide是否有机会这样做,但以匿名模式(私人浏览)?因为当您使用chrome创建进程时,选项:
#options.add_参数(“--incognito”)
不起作用。提前感谢。@scraper只需使用subprocess.Popen(“'C:\\Program Files\\Google\\Chrome\\Application\\Chrome.exe”--远程调试端口=9222'-匿名,shell=True)