如何解决在带有无头 Firefox 的共享 Dreamhost 服务器上运行 Selenium
阿罗哈,
我正在学习 Python 并使用 Selenium(因为使用 aspx 页面更容易)和 BeautifulSoup 做了一个网页抓取项目。我有它在我的个人 linux 机器上工作,但想将它移到我的共享主机 Dreamhost 帐户。我收到以下错误,并且没有任何想法。
已安装
Firefox 84 到 /home/[username]/bin/firefox 使用 mozilla 的说明。 https://support.mozilla.org/en-US/kb/install-firefox-linux 在没有包管理器的情况下安装,dreamhost 确实安装了 4 个主要依赖项
当我运行二进制文件 $ ~/bin/firefox/firefox
时,我得到“分段错误”,我认为这是因为它在服务器上并且它没有无头运行(还没有)。
Geckodriver 0.28.0 从 https://github.com/mozilla/geckodriver/releases
到 /home/[username]/bin/geckodriver我已经使用 .bashrc 将 /home/[username]/bin
添加到 $PATH(我认为这最终是不必要的,因为我必须在代码中定义位置)
我试图运行的代码看起来像
def dynamic_scrape():
from selenium import webdriver
from selenium.webdriver.support.ui import webdriverwait
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
firefox_binary = FirefoxBinary('/home/samami/bin/firefox/firefox')
options = Options()
options.headless = True
driver = webdriver.Firefox(options=options,firefox_binary=firefox_binary)
<REST OF CODE>
并注意我确实必须从我的工作代码中更改它并添加有关 firefox 二进制文件的行。我不知道这是否使它成为远程 selenium 使用。
输出
$ python3 scrapeCDS.py
Traceback (most recent call last):
File "scrapeCDS.py",line 71,in <module>
parsed_data = parse_tsr(dynamic_scrape())
File "scrapeCDS.py",line 19,in dynamic_scrape
driver = webdriver.Firefox(options=options,firefox_binary=firefox_binary)
File "/home/samami/.local/lib/python3.6/site-packages/selenium/webdriver/firefox/webdriver.py",line 174,in __init__
keep_alive=True)
File "/home/samami/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py",line 157,in __init__
self.start_session(capabilities,browser_profile)
File "/home/samami/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py",line 252,in start_session
response = self.execute(Command.NEW_SESSION,parameters)
File "/home/samami/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py",line 321,in execute
self.error_handler.check_response(response)
File "/home/samami/.local/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py",line 242,in check_response
raise exception_class(message,screen,stacktrace)
selenium.common.exceptions.WebDriverException: Message: Process unexpectedly closed with status signal
geckodriver.log 是
1608566388498 geckodriver INFO Listening on 127.0.0.1:34923
1608566388525 mozrunner::runner INFO Running command: "/home/samami/bin/firefox/firefox" "--marionette" "-headless" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofile4mmPvO"
感谢您的帮助!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。