Webscraping使用Selenium在Raspberry Pi Zero上:状态代码为:-4

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

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(&#39;--headless&#39;)

driver = webdriver.Chrome(executable_path=&#39;/usr/bin/chromedriver&#39;, options=chrome_options)  # Update with the actual path


driver.get(&quot;https://github.com/kaliiiiiiiiii/Selenium-Profiles&quot;)
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 &quot;/home/fanoeline/webscrapingexample.py&quot;, line 6, in &lt;module&gt;
    driver = webdriver.Chrome(executable_path=&#39;/usr/bin/chromedriver&#39;, options=chrome_options)  # Update with the actual path
  File &quot;/home/fanoeline/.local/lib/python3.9/site-packages/selenium/webdriver/chrome/webdriver.py&quot;, line 73, in __init__
    self.service.start()
  File &quot;/home/fanoeline/.local/lib/python3.9/site-packages/selenium/webdriver/common/service.py&quot;, line 98, in start
    self.assert_process_still_running()
  File &quot;/home/fanoeline/.local/lib/python3.9/site-packages/selenium/webdriver/common/service.py&quot;, 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 上通过无头配置解决问题的方式:

  1. 使用 Pi OS 的 Buster 版本刷写 SD 卡。

  2. 进行初始设置(需要连接键盘/鼠标/显示器),以加入网络、设置用户账户、时区等。

  3. 运行以下命令:

    sudo apt install --reinstall chromium-chromedriver

  4. 运行你的 Python 脚本,确保使用 python3 命令,因为 Buster 自带 Python 版本 2 和 3。

这对我有用,希望对你也有用。

英文:

OK, this is how I solved it on my Zero W with a headless config:

  1. Flash the SD card with the Buster version of the Pi OS.

Webscraping使用Selenium在Raspberry Pi Zero上:状态代码为:-4

  1. 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.

  2. Run the following command:

    sudo apt install --reinstall chromium-chromedriver

  3. 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.

huangapple
  • 本文由 发表于 2023年5月25日 02:29:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/76326452.html
匿名

发表评论

匿名网友

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

确定