exec: “google-chrome“: executable file not found in %PATH%

使用 chromedp时,启动程序报错:exec: "google-chrome": executable file not found in %PATH%

1.解决方案一:

        代码设置chrome谷歌浏览器路径       

2.解决方案二:

        在环境变量添加chrome.exe路径. 在path变量加入路径,注意不要~/chrome.exe

 

Traceback (most recent call last): File "/data/user/0/com.cscjapp.python/files/aarch64-linux-android/lib/python3.11/site-packages/selenium/webdriver/common/driver_finder.py", line 67, in _binary_paths output = SeleniumManager().binary_paths(self._to_args()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/data/user/0/com.cscjapp.python/files/aarch64-linux-android/lib/python3.11/site-packages/selenium/webdriver/common/selenium_manager.py", line 46, in binary_paths args = [str(self._get_binary())] + args ^^^^^^^^^^^^^^^^^^ File "/data/user/0/com.cscjapp.python/files/aarch64-linux-android/lib/python3.11/site-packages/selenium/webdriver/common/selenium_manager.py", line 93, in _get_binary raise WebDriverException(f"Unsupported platform/architecture combination: {sys.platform}/{arch}") selenium.common.exceptions.WebDriverException: Message: Unsupported platform/architecture combination: linux/aarch64 The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/data/user/0/com.cscjapp.python/files/ide_files/ide_run.py", line 31, in <module> start(fakepyfile,mainpyfile) File "/data/user/0/com.cscjapp.python/files/ide_files/ide_run.py", line 30, in start exec(open(mainpyfile).read(), __main__.__dict__) File "<string>", line 5, in <module> File "/data/user/0/com.cscjapp.python/files/aarch64-linux-android/lib/python3.11/site-packages/selenium/webdriver/chrome/webdriver.py", line 47, in __init__ super().__init__( File "/data/user/0/com.cscjapp.python/files/aarch64-linux-android/lib/python3.11/site-packages/selenium/webdriver/chromium/webdriver.py", line 53, in __init__ if finder.get_browser_path(): ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/data/user/0/com.cscjapp.python/files/aarch64-linux-android/lib/python3.11/site-packages/selenium/webdriver/common/driver_finder.py", line 47, in get_browser_path return self._binary_paths()["browser_path"] ^^^^^^^^^^^^^^^^^^^^ File "/data/user/0/com.cscjapp.python/files/aarch64-linux-android/lib/python3.11/site-packages/selenium/webdriver/common/driver_finder.py", line 78, in _binary_paths raise NoSuchDriverException(msg) from err selenium.common.exceptions.NoSuchDriverException: Message: Unable to obtain driver for chrome; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location /storage/emulated/0/Android/data/com.cscjapp.python/files/CJ_IDE/PythonProject/默认目录/王爷,计划/src $
最新发布
05-25
### 关于Python中Selenium `NoSuchDriverException` 和 BeautifulSoup `AttributeError: 'NoneType' object has no attribute 'string'` #### 一、关于Selenium中的`NoSuchDriverException` 此异常通常发生在尝试启动浏览器驱动程序时失败的情况。这可能是由于以下几个原因之一引起的: - **未安装或配置错误的WebDriver** 如果使用的浏览器是Google Chrome,则需要下载对应版本的ChromeDriver,并将其路径添加到系统的环境变量中或者直接指定其位置给Selenium使用[^1]。 ```python from selenium import webdriver chrome_driver_path = '/path/to/chromedriver' driver = webdriver.Chrome(executable_path=chrome_driver_path) ``` - **不兼容的WebDriver和浏览器版本** 确保所使用的WebDriver与实际安装的浏览器版本相匹配。如果不一致,可能会抛出此类异常[^2]。 #### 二、BeautifulSoup中的`AttributeError: 'NoneType' object has no attribute 'string'` 这种类型的错误表明,在调用`.string`方法之前,目标标签并未成功找到,即返回的是`None`而非预期的Tag对象[^3]。 - **原因分析** - HTML结构可能发生了变化,原先定义的选择器不再适用。 - 页面内容由JavaScript动态渲染而成,而普通的HTTP请求无法执行JS脚本从而获取不到完整的DOM树。 - **解决方案** - **验证元素存在与否** 在访问任何属性前先确认该元素确实已被检索出来。 ```python tag = soup.find('em', {'class': 'f-ff2'}) if tag is not None: print(tag.string) else: print("Element Not Found!") ``` - **采用更强大的工具处理动态加载的内容** 如前所述,对于依赖JavaScript生成的部分,可以考虑改用支持JS执行能力更强的库如Selenium来抓取数据后再交予BeautifulSoup解析。 --- ### 示例代码修正版 以下是综合运用Selenium与BeautifulSoup解决问题的一个例子: ```python from bs4 import BeautifulSoup as B from selenium import webdriver options = webdriver.ChromeOptions() options.add_argument('--headless') # 设置无界面模式 browser = webdriver.Chrome('/your/path/to/chromedriver', options=options) url = "https://music.163.com/song?id=1397248" browser.get(url) page_source = browser.page_source soup = B(page_source, 'html.parser') tag = soup.find('em', {'class': 'f-ff2'}) if tag is not None: print(tag.string) else: print("Target element does not exist.") browser.quit() # 记得关闭浏览器实例释放资源 ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值