我正在尝试使用Python通过Selenium webdriver打开网站。当我运行文件run.py
时,将打开一个空白的Firefox窗口。 10秒后,空白的Firefox窗口将自行关闭,并向我显示控制台和日志文件中的错误。
我如何通过Selenium webdriver打开该网站并获取HTML。
操作系统是Raspbian Stretch Python版本:3.5
run.py:
import spreadsheet
from bs4 import BeautifulSoup
from selenium import webdriver
profile = webdriver.FirefoxProfile()
driver = webdriver.Firefox(firefox_profile=profile, log_path='geckodriver.log')
driver.get('https://www.hackerearth.com/challenges/')
res = driver.execute_script("return document.documentElement.outerHTML")
driver.quit()
我进入终端时出错:
(eksilogin) pi@raspberrypi:~/Public/eksilogin $ python run.py
Traceback (most recent call last):
File "run.py", line 6, in <module>
driver = webdriver.Firefox(firefox_profile=profile, log_path='geckodriver.log')
File "/home/pi/.virtualenvs/eksilogin/lib/python3.5/site-packages/selenium/webdriver/firefox/webdriver.py", line 174, in __init__
keep_alive=True)
File "/home/pi/.virtualenvs/eksilogin/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/home/pi/.virtualenvs/eksilogin/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/home/pi/.virtualenvs/eksilogin/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/home/pi/.virtualenvs/eksilogin/lib/python3.5/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: connection refused
gecgodriver.log文件:
1547441749504 mozrunner::runner INFO Running command: "/usr/bin/firefox" "-marionette" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofile.Jdl9GCBGIGpH"
1547441752820 Marionette INFO Listening on port 2828
(firefox-esr:25183): Gdk-WARNING **: /home/pi/gtk+3.0-3.22.11/./gdk/x11/gdkproperty-x11.c:224 invalid X atom: 1994358852
(firefox-esr:25183): Gdk-WARNING **: /home/pi/gtk+3.0-3.22.11/./gdk/x11/gdkproperty-x11.c:224 invalid X atom: 1986538340
(firefox-esr:25183): Gdk-WARNING **: /home/pi/gtk+3.0-3.22.11/./gdk/x11/gdkproperty-x11.c:224 invalid X atom: 1986538344
(firefox-esr:25183): Gdk-WARNING **: /home/pi/gtk+3.0-3.22.11/./gdk/x11/gdkproperty-x11.c:224 invalid X atom: 1976671432
(firefox-esr:25183): Gdk-WARNING **: /home/pi/gtk+3.0-3.22.11/./gdk/x11/gdkproperty-x11.c:224 invalid X atom: 1986538344
(firefox-esr:25183): Gdk-WARNING **: /home/pi/gtk+3.0-3.22.11/./gdk/x11/gdkproperty-x11.c:224 invalid X atom: 281544
(firefox-esr:25183): Gdk-WARNING **: /home/pi/gtk+3.0-3.22.11/./gdk/x11/gdkproperty-x11.c:224 invalid X atom: 1995309056
(firefox-esr:25183): Gdk-WARNING **: /home/pi/gtk+3.0-3.22.11/./gdk/x11/gdkproperty-x11.c:224 invalid X atom: 1986538348
(firefox-esr:25183): Gdk-WARNING **: /home/pi/gtk+3.0-3.22.11/./gdk/x11/gdkproperty-x11.c:224 invalid X atom: 1976769928
(firefox-esr:25183): Gdk-WARNING **: /home/pi/gtk+3.0-3.22.11/./gdk/x11/gdkproperty-x11.c:224 invalid X atom: -582641408
(firefox-esr:25183): Gdk-WARNING **: /home/pi/gtk+3.0-3.22.11/./gdk/x11/gdkproperty-x11.c:224 invalid X atom: 1976671432
[Child 25254] ###!!! ABORT: Aborting on channel error.: file /build/firefox-esr-YKrXxr/firefox-esr-52.9.0esr/ipc/glue/MessageChannel.cpp, line 2152
[Child 25254] ###!!! ABORT: Aborting on channel error.: file /build/firefox-esr-YKrXxr/firefox-esr-52.9.0esr/ipc/glue/MessageChannel.cpp, line 2152
###!!! [Child][MessageChannel] Error: (msgtype=0x3E0003,name=PCompositable::Msg_Destroy) Channel error: cannot send/recv
###!!! [Child][MessageChannel] Error: (msgtype=0x3E0003,name=PCompositable::Msg_Destroy) Channel error: cannot send/recv