【问题标题】:Unable to access site with python selenium webdriver无法使用 python selenium webdriver 访问站点
【发布时间】:2021-04-28 09:24:27
【问题描述】:

我一直在尝试构建一个通用刮刀。但不知何故,有些网站由于某种原因我无法访问。

我尝试使用互联网上提供的各种选项来确保我避免了机器人检测标志,但不知何故该网站显然“检测到”我是机器人。

这是我一直在使用的选项。

```options.add_argument("--disable-blink-features")
options.add_argument("--disable-blink-features=AutomationControlled")
options.add_argument("user-data-dir=" + r'C:\Users\JEGSTUDIO\AppData\Local\Google\Chrome\selenium')
options.add_argument("window-size=1280,800")
options.add_argument("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)```

我查看并比较了 cookie,根据 cookie 命名,该站点似乎正在使用 Cloudflare js。

https://support.cloudflare.com/hc/en-us/articles/200170136-Understanding-Cloudflare-Challenge-Passage-Captcha-

这是完整的代码,你们可以试试

```from selenium import webdriver

options = webdriver.ChromeOptions()

options.add_argument("--disable-blink-features")
options.add_argument("--disable-blink-features=AutomationControlled")
options.add_argument("user-data-dir=" + r'C:\Users\JEGSTUDIO\AppData\Local\Google\Chrome\selenium')
options.add_argument("window-size=1280,800")
options.add_argument("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)

driver = webdriver.Chrome(options=options, executable_path=r'C:\Users\JEGSTUDIO\Gochi\Scraping Project\Scraper - AITOPIA v2\chromedriver88crack.exe')

driver.execute_script("Object.defineProperty(navigator, 'webdriver', {get: () => undefined})")

driver.get("https://google.com")

input('Next site')

driver.get("https://www.harrods.com/")

input('enter to quit')

driver.quit()```

任何线索将不胜感激

【问题讨论】:

    标签: python selenium web-scraping selenium-chromedriver bots


    【解决方案1】:
    options.add_argument("--remote-debugging-port=9222")
    
    options.add_argument(
        "user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36")
    options.add_experimental_option("excludeSwitches", ["enable-automation"])
    
    
    
    driver = webdriver.Chrome(options=options)
    
    driver.maximize_window()
    
    
    driver.get("https://www.harrods.com/")
    

    添加远程调试端口使网站正常工作

    【讨论】:

      猜你喜欢
      • 2022-12-14
      • 2020-10-17
      • 2021-06-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-21
      • 2021-03-02
      • 2016-08-26
      相关资源
      最近更新 更多