我在EC2实例上.所以没有GUI.
$pip install selenium
$sudo apt-get install firefox xvfb
Run Code Online (Sandbox Code Playgroud)
然后我这样做:
$Xvfb :1 -screen 0 1024x768x24 2>&1 >/dev/null &
$DISPLAY=:1 java -jar selenium-server-standalone-2.0b3.jar
05:08:31.227 INFO - Java: Sun Microsystems Inc. 19.0-b09
05:08:31.229 INFO - OS: Linux 2.6.32-305-ec2 i386
05:08:31.233 INFO - v2.0 [b3], with Core v2.0 [b3]
05:08:32.121 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub
05:08:32.122 INFO - Version Jetty/5.1.x
05:08:32.123 INFO - Started HttpContext[/selenium-server/driver,/selenium-server/driver]
05:08:32.124 INFO - Started HttpContext[/selenium-server,/selenium-server]
05:08:32.124 INFO - Started HttpContext[/,/]
05:08:32.291 INFO - Started org.openqa.jetty.jetty.servlet.ServletHandler@1186fab …Run Code Online (Sandbox Code Playgroud) 我已经在我的centos6.4服务器上安装了firefox和Xvfb来使用selenium webdriver.
但是,当我运行代码时,我收到了一个错误.
from selenium import webdriver
browser = webdriver.Firefox()
Run Code Online (Sandbox Code Playgroud)
错误
selenium.common.exceptions.WebDriverException: Message:
'The browser appears to have exited before we could connect. The output was: None'
Run Code Online (Sandbox Code Playgroud)
我在stackoverflow上读了一些相关的页面,有人建议删除tmp文件夹中的所有文件,所以我做到了.但是,它仍然无效.
有人可以帮我一个忙吗?
先感谢您!
编辑
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.4/site-packages/selenium/webdriver/firefox/webdriver.py", line 59, in __init__
self.binary, timeout),
File "/usr/local/lib/python3.4/site-packages/selenium/webdriver/firefox/extension_connection.py", line 47, in __init__
self.binary.launch_browser(self.profile)
File "/usr/local/lib/python3.4/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 64, in launch_browser
self._wait_until_connectable()
File "/usr/local/lib/python3.4/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 103, in _wait_until_connectable
self._get_firefox_output())
selenium.common.exceptions.WebDriverException: Message: 'The browser appears to have exited before …Run Code Online (Sandbox Code Playgroud) 我花了最近几天把Selenium,Tor和Firefox作为多项任务的组合.我已经设法在Python中编写了一个简单的脚本,通过Selenium控制Firefox,而Firefox则连接到Tor以保护隐私.
现在,我正在寻找一种节省资源的方法,所以我想在无头模式下运行Firefox,我认为这是一个常见的功能,但似乎并不是这样.我正在寻找一种方法来做到这一点.它是Firefox而不是某些基于终端的浏览器的原因是因为我在Firefox中使用的扩展"TorButton".它内置了javascript注入,有助于隐私.
如果有人之前做过这件事(我相信很多人都有!),我们将非常感谢你们的一些提示,谢谢!
我正在抓一些似乎有很好保护的网站.我可以让它工作的唯一方法是使用Selenium加载页面,然后从中抓取东西.
目前这适用于我的本地计算机(当我访问我的页面时,firefox窗口打开并关闭,并且我的脚本中的HTML将被进一步处理).但是,我需要在网上访问我的刮刀.刮刀嵌入在Heroku上的Flask应用程序中.有没有办法让Selenium浏览器在Heroku服务器上运行?或者是否有任何托管服务提供商可以工作?
在我的Linux系统中,我使用Firefox,执行我的程序,我的错误是:
Traceback (most recent call last):
File "shenma_diff_main_v2.py", line 90, in <module>
browser = webdriver.Firefox(profile)
File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 59, in __init__
self.binary, timeout),
File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/firefox/extension_connection.py", line 47, in __init__
self.binary.launch_browser(self.profile)
File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 66, in launch_browser
self._wait_until_connectable()
File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 100, in _wait_until_connectable
raise WebDriverException("The browser appears to have exited "
selenium.common.exceptions.WebDriverException: Message: The browser appears to have exited before we could connect. If you specified a log_file in the FirefoxBinary constructor, check it for details.
Run Code Online (Sandbox Code Playgroud)
如果我使用root执行我的程序就可以了.