2016-07-24 57 views
-2

我在Windows 7上运行这里美丽的汤4.5与Python 3.4是我的脚本:Beautfil汤错误与简单的脚本

from bs4 import BeautifulSoup 
import urllib3 

http = urllib3.PoolManager() 

url = 'https://scholar.google.com' 
response = http.request('GET', url) 
html2 = response.read() 
soup = BeautifulSoup([html2]) 

print (type(soup)) 

这里是我得到的错误:

TypeError: Expected String or Buffer

我已经研究过,似乎没有任何修复,除了去一个我不想做的美丽的汤的旧版本。任何帮助将非常感激。

回答

0

不知道你为什么把HTML字符串到列表中的位置:

​​

将其替换为:

soup = BeautifulSoup(html2) 

或者,您也可以通过响应文件对象,BeautifulSoup会为你解读:

response = http.request('GET', url) 
soup = BeautifulSoup(response) 

这也是一个好主意,明确指定解析器:

soup = BeautifulSoup(html2, "html.parser") 
+0

谢谢!我以为我尝试过,但我猜不是,因为那样摆脱了错误信息。 – user235511

+0

完成。和thx家伙。 – user235511