python-3.x - 刮硒保护地
问题描述
我遇到了能够自动化的问题(网站(点击这里))
看来该站点在某种程度上受到 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 实现自动化,以及是否有任何可能的解决方法。如果没有,也许你有一个建议可以分享,从另一个角度解决。
解决方案
更多关于您的用例以及您为什么觉得...该站点受到保护...将有助于我们进一步分析问题。但是通过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/
奥特罗
您可以在以下位置找到一些相关的讨论:
推荐阅读
- laravel - Laravel:为什么急切加载只保留最后一个模型的结果?
- r - 每周频率 - 透析数据集
- groovy - 检查是否直接执行 Groovy 脚本
- java - 休息 API 端点
- css - Mozilla Firefox 和 Internet Explorer 中的 CSS 不同输出
- python - 插值 3D,其中 z 是一个数组
- java - 在 Java 中获取系统属性
- javascript - 如何删除从 razor var 生成的 html 到 Javascript 变量?
- scala - 如何按列表中的键分组
- amazon-web-services - 让多个 AWS Lambda 使用外部(EC2)Postgres 的最佳实践是什么