2013-10-15 20 views
0

我一直在試圖讓Python中的.text thingy將html代碼轉換爲可讀文本來工作,但仍然沒有運氣。Python的.text:無法讓它起作用

比方說,我有以下代碼:

import urllib 

url = ['http://google.com','http://bing.com'] 

for i in url: 
    html = urllib.urlopen(i).read() 
    print html.encode('utf-8').text 

代碼工作,一旦我刪除最後一行的.text,但我已經看到了使用在教程沒有任何問題,在所有的人。任何想法爲什麼我不能得到它的工作?大聲笑

非常感謝!

+0

字符串沒有'文本'屬性....從來沒有,永遠不會 –

+0

BeautifulSoup元素有一個文本屬性...這就是這對我來說是什麼。 – DivinusVox

+0

BeautifulSoup在這裏使用了哪裏? –

回答

0
import urllib 

url = ['http://google.com','http://bing.com'] 

for i in url: 
    html = urllib.urlopen(i).read() 
    print html 

無需encodetext,正好可以read()後打印html寫。我建議你使用python-requests

+0

爲什麼downvote? –