1

我喜欢 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 上的文档表明,硒“只有在您有 Selenium 服务器指向时才在 ScraperWiki 中有用。” 我不知道他们对此的确切含义,但我认为这可能是问题的原因。任何帮助将不胜感激。

4

1 回答 1

1

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 限制了您可以连接到互联网的端口,因此您可能需要使用另一个端口(可能是端口 80)而不是使用端口 4444。

总而言之,我认为这可能不是一个可行的解决方案,你最好用 python、php 或 ruby​​ 编写你的爬虫。

于 2013-01-18T14:56:12.973 回答