2015-04-30 63 views
-5

这是使用NLTK的文本摘要守则的一部分:我试图运行,下面这段代码,这是给我的错误

import urllib 
feed_xml = urllib.urlopen('http://feeds.bbci.co.uk/news/rss.xml').read() 
feed = BeautifulSoup(feed_xml.decode('utf8')) 
to_summarize = map(lambda p: p.text, feed.find_all('guid')) 
fs = FrequencySummarizer() 
for article_url in to_summarize[:5]: 
    title, text = get_only_text(article_url) 
    print ('----------------------------------') 
    print (title) 
for s in fs.summarize(text, 2): 
    print ('*',s) 

以下是错误

C:\Python34>2.py 
Traceback (most recent call last): 
File "C:\Python34\2.py", line 2, in <module> 
feed_xml = urllib.urlopen('http://feeds.bbci.co.uk/news/rss.xml').read() 
AttributeError: 'module' object has no attribute 'urlopen' 
+0

你到现在为止尝试本地化你的错误?告诉我们你的努力。 – Aracthor

+2

如果你想知道你的问题为什么被低估:最可能的原因是你的头衔相当可怕(描述问题本身,不是你有问题,*所有*问题都要求帮助),错误信息是微不足道的,可以随时找到你的答案。 –

回答

1

尝试urllib.request.urlopen()代替urllib.urlopen()

+0

我试过.......给我一个新的错误“模块没有属性请求” –

+0

,你试过'urllib2.urlopen()',以防万一? –

相关问题