首页 > 解决方案 > 刮硒保护地

问题描述

我遇到了能够自动化的问题(网站(点击这里)

看来该站点在某种程度上受到 chromedriver 的保护。当我正常访问该网站时,我没有问题,但是当 selenium 尝试使该网站自动化时,该 url 会重定向到其他主页。

这是我的示例代码:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time

chrome_options = Options()
#chrome_options.add_argument("--headless")

EXE_PATH = 'chromedriver.exe'
driver = webdriver.Chrome(executable_path=EXE_PATH)#, options=chrome_options)
driver.get(SEE URL ABOVE)
time.sleep(5)
print(driver.current_url)
driver.quit()

请使用超链接文本中的链接。我在这里从我的代码中删除了它。

想知道是否有人遇到过类似的问题,网站发现浏览器正在使用 selenium 实现自动化,以及是否有任何可能的解决方法。如果没有,也许你有一个建议可以分享,从另一个角度解决。

标签: python-3.xseleniumgoogle-chromeweb-scrapingselenium-chromedriver

解决方案


更多关于您的用例以及您为什么觉得...该站点受到保护...将有助于我们进一步分析问题。但是通过Selenium访问该站点,您可以使用以下解决方案:

  • 代码块:

    from selenium import webdriver
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    
    options = webdriver.ChromeOptions()
    options.add_argument("start-maximized")
    #options.add_argument("--headless")
    options.add_experimental_option("excludeSwitches", ["enable-automation"])
    options.add_experimental_option('useAutomationExtension', False)
    driver = webdriver.Chrome(options=options, executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
    driver.get("https://publicindex.sccourts.org/horry/publicindex/")
    WebDriverWait(driver, 10).until(EC.title_contains("Index"))
    print(driver.current_url)
    driver.quit()
    
  • 控制台输出:

    https://publicindex.sccourts.org/horry/publicindex/
    

奥特罗

您可以在以下位置找到一些相关的讨论:


推荐阅读