Python 覆盆子皮&x2B;硒+;无头Firefox/Iceweasel-Can';t载荷剖面

Python 覆盆子皮&x2B;硒+;无头Firefox/Iceweasel-Can';t载荷剖面,python,firefox,selenium,raspberry-pi,xvfb,Python,Firefox,Selenium,Raspberry Pi,Xvfb,目标:Raspberry Pi的高效无头浏览(使用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() #

目标:Raspberry Pi的高效无头浏览(使用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.
  • (使用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.
错误:

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.
回溯(最近一次呼叫最后一次):
文件“/home/pi/Desktop/mail finder.py”,第18行,在
browser=webdriver.Firefox()
文件“/usr/local/lib/python3.2/dist-packages/selenium/webdriver/firefox/webdriver.py”,第59行,在__
self.binary,超时),
文件“/usr/local/lib/python3.2/dist-packages/selenium/webdriver/firefox/extension\u connection.py”,第47行,在__
self.binary.launch_浏览器(self.profile)
文件“/usr/local/lib/python3.2/dist packages/selenium/webdriver/firefox/firefox\u binary.py”,第66行,在启动浏览器中
self.\u等待\u直到\u可连接()
文件“/usr/local/lib/python3.2/dist packages/selenium/webdriver/firefox/firefox\u binary.py”,第105行,在“等待”直到“可连接”
引发WebDriverException(“无法加载配置文件。配置文件”
selenium.common.exceptions.WebDriverException:消息:无法加载配置文件。配置文件目录:%s如果您在FirefoxBinary构造函数中指定了日志文件,请检查它以了解详细信息。

为什么不在headless中使用PhantomJs?对于linux/raspberry pi来说,我很好奇,我相信你必须从源代码构建PhantomJs。这个过程看起来很复杂,我不知道如何解决这个问题。你不必自己编译PhantomJs,这里有一个编译版本: