Selenium BeautifulSoup奇怪的错误

时间:2012-12-13 12:24:36

标签: python django selenium beautifulsoup

在我的Django应用程序中,我使用selenium来获取页面,使用BeautifulSoup来解析html。我和Xvfb一起在Debian工作。这是代码:

from selenium import webdriver
import os

os.environ["DISPLAY"]=":99"
driver = webdriver.Firefox()
driver.get("www.google.it")
text = driver.page_source

soup = BeautifulSoup(text)  

(... some code to parse the page with ...)

我有一个非常奇怪的错误:如果我搜索“汤”,则找不到任何内容。这不会发生在我的本地Windows XP计算机上。在“文本”中有html。

更新:我认为这可能是编解码器/解码器错误,但在这种情况下我不知道如何处理它。

1 个答案:

答案 0 :(得分:0)

您实际上并未抓取该页面,因此无需解析。 WebDriver需要一个有效的网址(以&#34开头; http://"或" https://")

您应该更改以下行:

driver.get("www.google.it")

为:

driver.get("http://www.google.it")