目标: Raspberry Pi的高效无头浏览(使用Python 3)
我尝试过的事情:
(使用pip-3.2)安装:selenium v2.45.0,pyvirtualdisplay v0.1.5
(使用apt-get)已安装:xvfb(最新我认为是v1.12.4?),iceweasel v31.5.3
Python 3代码:
from selenium import webdriver
from pyvirtualdisplay import Display
display = Display(visibile=0, size=(800, 600)) # NOTE: Seems to work (non-headless)
display.start() # without these 2 lines
browser = webdriver.Firefox()
browser.get('http://www.google.com')
print(browser.page_source)
browser.quit()
错误:
Traceback (most recent call last):
File "/home/pi/Desktop/mail-finder.py", line 18, in <module>
browser = webdriver.Firefox()
File "/usr/local/lib/python3.2/dist-packages/selenium/webdriver/firefox/webdriver.py", line 59, in __init__
self.binary, timeout),
File "/usr/local/lib/python3.2/dist-packages/selenium/webdriver/firefox/extension_connection.py", line 47, in __init__
self.binary.launch_browser(self.profile)
File "/usr/local/lib/python3.2/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 66, in launch_browser
self._wait_until_connectable()
File "/usr/local/lib/python3.2/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 105, in _wait_until_connectable
raise WebDriverException("Can't load the profile. Profile "
selenium.common.exceptions.WebDriverException: Message: Can't load the profile. Profile Dir: %s If you specified a log_file in the FirefoxBinary constructor, check it for details.