2013-10-15 23 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? –