driver = webdriver.Chrome() :: 使用Selenium方法时的问题 – 如何解决

huangapple go评论109阅读模式
英文:

driver = webdriver.Chrome() :: issues with a selenium approach - how to work around

问题

Here is the translation of the non-code part of your text:

"我正在尝试找出从 clutch.io 收集数据的最简单方法,我尝试了各种方法来从网站 (clutch.io) 收集数据,但似乎都失败了。如下所示:"

"如何解决这个问题?我正在尝试找出从 clutch.io 收集数据的最简单方法。"

Please note that I've excluded the code part from the translation as per your request. If you have any specific questions related to the code or need assistance with it, please feel free to ask.

英文:

Well - i am trying to figure out the simplest approach to gather data from clutch.io

  • i have tried various approaches to gather data from a website (clutch.io ) but all seems to fail:

see here

from bs4 import BeautifulSoup
from selenium import webdriver

driver = webdriver.Chrome()

url = 'https://clutch.co/it-services/msp'

driver.get(url=url)
soup = BeautifulSoup(driver.page_source,"lxml")

links = []
for l in soup.find_all('li',class_='website-link website-link-a'):
    results = (l.a.get('href'))
    links.append(results)

print(links, "\n", "Count links - ", len(links))

throws back this error:

---------------------------------------------------------------------------
WebDriverException                        Traceback (most recent call last)
<ipython-input-4-4f37092106f4> in <cell line: 4>()
      2 from selenium import webdriver
      3 
----> 4 driver = webdriver.Chrome()
      5 
      6 url = 'https://clutch.co/it-services/msp'

5 frames
/usr/local/lib/python3.10/dist-packages/selenium/webdriver/remote/errorhandler.py in check_response(self, response)
    243                 alert_text = value["alert"].get("text")
    244             raise exception_class(message, screen, stacktrace, alert_text)  # type: ignore[call-arg]  # mypy is not smart enough here
--> 245         raise exception_class(message, screen, stacktrace)

WebDriverException: Message: unknown error: cannot find Chrome binary
Stacktrace:
#0 0x55a6ebf424e3 <unknown>
#1 0x55a6ebc71c76 <unknown>
#2 0x55a6ebc98757 <unknown>
#3 0x55a6ebc97029 <unknown>
#4 0x55a6ebcd5ccc <unknown>
#5 0x55a6ebcd547f <unknown>
#6 0x55a6ebcccde3 <unknown>
#7 0x55a6ebca22dd <unknown>
#8 0x55a6ebca334e <unknown>
#9 0x55a6ebf023e4 <unknown>
#10 0x55a6ebf063d7 <unknown>
#11 0x55a6ebf10b20 <unknown>
#12 0x55a6ebf07023 <unknown>
#13 0x55a6ebed51aa <unknown>
#14 0x55a6ebf2b6b8 <unknown>
#15 0x55a6ebf2b847 <unknown>
#16 0x55a6ebf3b243 <unknown>
#17 0x7ffb30c27609 start_thread

how to work around!?
Well - i am trying to figure out the simplest approach to gather data from clutch.io

答案1

得分: 2

This error message...

WebDriverException: Message: 未知错误: 无法找到 Chrome 二进制文件

...意味着ChromeDriver无法在系统的默认位置找到[tag:google-chrome]二进制文件,或者根本没有安装它。


在非标准位置使用 Chrome 可执行文件

您需要使用以下方式覆盖默认的_Chrome 二进制文件位置_,使用 自定义位置

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

options = Options()
options.binary_location = "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe" # 根据我的 Win10 操作系统
s = Service('C:\\BrowserDrivers\\chromedriver.exe')
driver = webdriver.Chrome(service=s, options=options)
driver.get('http://google.com/')
print("Chrome 浏览器已启动")

参考资料

您可以在以下链接中找到一些相关的详细讨论:

英文:

This error message...

WebDriverException: Message: unknown error: cannot find Chrome binary

...implies that the ChromeDriver was unable to find the [tag:google-chrome] binary in the default location of your system or it wasn't installed at all.


Using a Chrome executable in a non-standard location

You need to override the default Chrome binary location with the custom location as follows:

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

options = Options()
options.binary_location = "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe" # as per my Win10 OS box
s = Service('C:\\BrowserDrivers\\chromedriver.exe')
driver = webdriver.Chrome(service=s, options=options)
driver.get('http://google.com/')
print("Chrome Browser Invoked")

References

You can find a couple of relevant detailed discussions in:

huangapple
  • 本文由 发表于 2023年6月6日 02:27:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/76409097.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定