我喜欢selenium,我也喜欢scraperwiki,但不知何故,我不能让它们在一起正常工作。我尝试过在scraperwiki上使用selenium以两种方式打开网站,这两种方法都是从教程中获得的:
import selenium
sel = selenium.selenium("localhost",4444,"*firefox", "http://www.google.com")
sel.open("http://google.com")这不起作用。它给出了以下错误:
error: [Errno 111] Connection refused 这一点也不是:
from selenium import webdriver
browser = webdriver.Firefox()这给出了另一个错误:
/usr/lib/python2.7/subprocess.py:672 -- __init__((self=<subprocess.Popen object at 0x1d14410>, args=[None, '-silent'], bufsize=0, executable=None, stdin=None, stdout=-1, stderr=-1, preexec_fn=None, close_fds=False, shell=False, cwd=None, env=None, universal_newlines=False, startupinfo=None, creationflags=0))
AttributeError: 'NoneType' object has no attribute 'rfind'有没有人看到这是一个合理的原因?
scraperwiki上的文档指出,seleneium“只有在有Selenium服务器指向它的情况下才在ScraperWiki中有用”。我不知道这到底是什么意思,但我认为这可能是问题的原因。任何帮助都将不胜感激。
发布于 2013-01-18 22:56:13
Selenium不仅仅是您正在使用的Python库,它还有一个单独的软件,即问题中提到的Selenium服务器,它代表您的代码与浏览器交互。
这行代码
sel = selenium.selenium("localhost",4444,"*firefox", "http://www.google.com") 正在尝试连接到Selenium服务器,以便它可以按照代码的要求向浏览器(Firefox)发送命令。脚本上下文中的"localhost“是ScraperWiki的服务器之一,它没有运行selenium服务器。
您需要做的是下载http://selenium.googlecode.com/files/selenium-server-standalone-2.28.0.jar并将其安装在另一台服务器上,运行它
java -jar selenium-server-standalone-2.28.0.jar然后,您可以将您的代码更改为指向正在运行它的服务器。这会变得更加复杂,因为ScraperWiki限制了您可以连接到internet的端口,所以您可能需要使用另一个端口(可能是端口80),而不是使用端口4444。
总而言之,我认为这可能不是一个可行的解决方案,你最好用python、php或ruby编写你的scraper。
https://stackoverflow.com/questions/14283661
复制相似问题