【问题标题】:scraping selenium protected site刮硒保护地
【发布时间】:2019-11-06 04:06:04
【问题描述】:

我遇到了能够自动化的问题 (website (clickhere))

该网站似乎在某种程度上受到 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.x selenium google-chrome web-scraping selenium-chromedriver


    【解决方案1】:

    更多地了解您的用例以及为什么您觉得...该网站受到保护...将有助于我们进一步分析问题。但是通过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/
      

    结尾

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

    【讨论】:

      猜你喜欢
      • 2020-08-23
      • 2017-06-18
      • 2011-03-24
      • 1970-01-01
      • 1970-01-01
      • 2019-08-31
      • 2016-01-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多