我试图在下面运行此代码,这给了我错误

时间:2015-04-30 07:28:00

标签: python rss

这是使用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'

1 个答案:

答案 0 :(得分:1)

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

相关问题