2015-04-30 107 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()',以防萬一? –

相關問題