未检测到的 Chromedriver 未正确加载
Posted
技术标签:
【中文标题】未检测到的 Chromedriver 未正确加载【英文标题】:Undetected Chromedriver not loading correctly 【发布时间】:2021-04-08 07:20:29 【问题描述】:我正在尝试使用带有 selenium 的无头 chrome 浏览器,它也绕过了机器人检测测试,目前正在使用以下项目 https://github.com/ultrafunkamsterdam/undetected-chromedriver 每次我尝试实现代码时,它都无法识别驱动程序。 Here is the link for you to understand
这里是代码
#
# UNDETECTED chromedriver (headless,even)
#
import undetected_chromedriver as uc
options = uc.ChromeOptions()
options.headless=True
options.add_argument('--headless')
chrome = uc.Chrome(options=options)
chrome.get('https://datadome.co/customers-stories/toppreise-ends-web-scraping-and-content-theft-with-datadome/')
chrome.save_screenshot('datadome_undetected_webddriver.png')
所以当我使用 chrome.get()
时,我收到一个错误,因为 chrome 没有 get()
成员。
我也使用 pip 命令安装了该项目。所以我在想我是否需要指向 chromedriver 的路径,那会在哪里,因为我怀疑它会是普通的驱动程序,并且文档从未提到驱动程序的 PATH。
好的,所以当我运行程序时,我会在终端中得到以下信息
DevTools listening on ws://127.0.0.1:55903/devtools/browser/ef3a54cf-35b9-400f-972c-2b54ca227eb8
[0102/000855.199:INFO:CONSOLE(2)] "JQMIGRATE: Migrate is installed, version 1.4.1", source: https://datadome.co/wp-content/cache/busting/1/wp-includes/js/jquery/jquery-migrate.min-1.4.1.js (2)
[0102/000856.946:INFO:CONSOLE(1)] "Messaging child iframes", source: https://track.gaconnector.com/gaconnector.js (1)
[0102/000856.946:INFO:CONSOLE(1)] "https://track.gaconnector.com/track_pageview?gaconnector_id=ddade4fc-93d0-20a3-79fa-39648d8e6629&account_id=6dd3433635353fd00f486550bcd5b157&referer=&GA_Client_ID=183291439.1609510136&page_url=https%3A%2F%2Fdatadome.co%2Fcustomers-stories%2Ftoppreise-ends-web-scraping-and-content-theft-with-datadome%2F&gclid=&utm_campaign=&utm_term=&utm_content=&utm_source=&utm_medium=", source: https://track.gaconnector.com/gaconnector.js (1)
PS D:\Programming\Python> [0102/000902.158:INFO:CONSOLE(0)] "The resource https://js.driftt.com/core/assets/js/runtime~main.a73a2727.js was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: https://js.driftt.com/core?embedId=2rce7xnshapc&forceShow=false&skipCampaigns=false&sessionId=98163ad1-ed91-459e-9473-3f8861aa717e&sessionStarted=1609510138&campaignRefreshToken=107a7fd5-edb4-499b-9f39-5306c189cdb6&pageLoadStartTime=1609510135613 (0)
[0102/000902.272:ERROR:web_contents_delegate.cc(224)] WebContentsDelegate::CheckMediaAccessPermission: Not supported.
[0102/000902.272:ERROR:web_contents_delegate.cc(224)] WebContentsDelegate::CheckMediaAccessPermission: Not supported.
[0102/000902.475:INFO:CONSOLE(0)] "The resource https://js.driftt.com/core/assets/js/runtime~main.a73a2727.js was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: https://js.driftt.com/core/chat (0)
[0102/000906.041:INFO:CONSOLE(0)] "The resource https://js.zohocdn.com/ichat/js/73291e5e_wmsbridge.js was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: https://datadome.co/customers-stories/toppreise-ends-web-scraping-and-content-theft-with-datadome/ (0)
【问题讨论】:
看来需要把chromdriver路径放到环境变量PATH里面。据我所知。 我已将 chrome 驱动程序添加到变量 PATH 中,但仍然没有。我什至将它作为参数 "options = uc.ChromeOptions('D:/Programming/chromedriver.exe')" 总是将完整的错误消息(从单词“Traceback”开始)放在有问题的(不是commnt)作为分机而不是屏幕截图)。还有其他有用的信息。 【参考方案1】:ChromeOptions()
在selenium.webdriver.chrome.options 中定义,但不在undetected_chromedriver 中。
解决方案
您可以使用以下解决方案:
代码块:
import undetected_chromedriver as uc
from selenium import webdriver
options = webdriver.ChromeOptions()
options.headless = True
driver = uc.Chrome(options=options)
driver.get('https://datadome.co/customers-stories/toppreise-ends-web-scraping-and-content-theft-with-datadome/')
driver.save_screenshot('datadome_undetected_webddriver.png')
driver.quit()
print("Program Ended")
控制台输出:
截图:参考
您可以在以下位置找到一些相关的详细讨论:
Is there any possible ways to bypass cloudflare security checks?【讨论】:
对于未来的读者:在最新版本 2.2.1 中,我可以使用 UC 的 ChromeOptions 没有任何问题,因此我们不需要使用 Selenium 的 chrome 选项。 UC 的 ChromeOptions 中有修复,所以我们应该使用这个选项而不是 Selenium。以上是关于未检测到的 Chromedriver 未正确加载的主要内容,如果未能解决你的问题,请参考以下文章