英文:
Webscraping using Selenium on Raspberry Pi Zero: Status code was: -4
问题
我非常新于网络抓取/编程/树莓派。我试图使用一个无头的树莓派零进行网络抓取。我正在根据下面显示的示例进行工作:
from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
driver = webdriver.Chrome(executable_path='/usr/bin/chromedriver', options=chrome_options) # 请更新为实际路径
driver.get("https://github.com/kaliiiiiiiiii/Selenium-Profiles")
print(driver.title)
driver.quit()
我将此文件保存为"webscrapingexample.py",并将其移动到我的树莓派上,然后使用$ python webscrapingexample.py运行它。这给了我以下错误:
$ python webscrapingexample.py
Traceback (most recent call last):
File "/home/fanoeline/webscrapingexample.py", line 6, in <module>
driver = webdriver.Chrome(executable_path='/usr/bin/chromedriver', options=chrome_options) # 请更新为实际路径
File "/home/fanoeline/.local/lib/python3.9/site-packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__
self.service.start()
File "/home/fanoeline/.local/lib/python3.9/site-packages/selenium/webdriver/common/service.py", line 98, in start
self.assert_process_still_running()
File "/home/fanoeline/.local/lib/python3.9/site-packages/selenium/webdriver/common/service.py", line 109, in assert_process_still_running
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: Service /usr/bin/chromedriver unexpectedly exited. Status code was: -4
有人能帮助我理解我做错了什么吗?我认为"-4"状态代码与系统无法打开文件有关?我已经尝试安装和重新安装了selenium、chromium等。
英文:
I am very new to web scraping/coding/raspberry pi. I am trying to web scrape using a headless Raspberry Pi zero. I am working off the example shown below:
from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
driver = webdriver.Chrome(executable_path='/usr/bin/chromedriver', options=chrome_options) # Update with the actual path
driver.get("https://github.com/kaliiiiiiiiii/Selenium-Profiles")
print(driver.title)
driver.quit()
I have saved this file as "webscrapingexample.py", moved it onto my Raspberry Pi, where I am running it using $ python webscrapingexample.py. This gives me the following error:
$ python webscrapingexample.py
Traceback (most recent call last):
File "/home/fanoeline/webscrapingexample.py", line 6, in <module>
driver = webdriver.Chrome(executable_path='/usr/bin/chromedriver', options=chrome_options) # Update with the actual path
File "/home/fanoeline/.local/lib/python3.9/site-packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__
self.service.start()
File "/home/fanoeline/.local/lib/python3.9/site-packages/selenium/webdriver/common/service.py", line 98, in start
self.assert_process_still_running()
File "/home/fanoeline/.local/lib/python3.9/site-packages/selenium/webdriver/common/service.py", line 109, in assert_process_still_running
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: Service /usr/bin/chromedriver unexpectedly exited. Status code was: -4
Can anyone help me understand what I am doing wrong? I think the "-4" status code has something to do with the system not being able to open the file?
I have tried installing and re-installing selenium, chromium etc.
答案1
得分: 1
好的,这是我在我的 Zero W 上通过无头配置解决问题的方式:
-
使用 Pi OS 的 Buster 版本刷写 SD 卡。
-
进行初始设置(需要连接键盘/鼠标/显示器),以加入网络、设置用户账户、时区等。
-
运行以下命令:
sudo apt install --reinstall chromium-chromedriver
-
运行你的 Python 脚本,确保使用 python3 命令,因为 Buster 自带 Python 版本 2 和 3。
这对我有用,希望对你也有用。
英文:
OK, this is how I solved it on my Zero W with a headless config:
- Flash the SD card with the Buster version of the Pi OS.
-
Run through the initial setup (you will need to connect keyboard / mouse / monitor) to get it joined to the network, setup user accounts, time zones etc.
-
Run the following command:
sudo apt install --reinstall chromium-chromedriver
-
Run your Python script making sure to use the python3 command, as Buster comes with Python version 2 and 3.
This got it going for me, hopefully it will work for you as well.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论