2016-07-24 67 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