这是使用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 :(得分:1)
尝试使用urllib.request.urlopen()
代替urllib.urlopen()