本文整理匯總了Python中readability.Document.encode方法的典型用法代碼示例。如果您正苦於以下問題:Python Document.encode方法的具體用法?Python Document.encode怎麽用?Python Document.encode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類readability.Document
的用法示例。
在下文中一共展示了Document.encode方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: int
# 需要導入模塊: from readability import Document [as 別名]
# 或者: from readability.Document import encode [as 別名]
number_of_links = int(sys.argv[1])
query = '+'.join(sys.argv[2:])
regex = re.compile("<(.*?)>|\ ")
article_list = []
summary_list = []
links = GoogleNews.search(query,number_of_links) #Perform Google News search
if not links:
print "No links found" #If no links for a query then..
else:
for l in links:
html = urllib2.urlopen(l).read()
article = Document(html).summary()
article = re.sub(regex, "", article)
article = article.encode('ascii','ignore')
ss = summarize.SimpleSummarizer()
summary = ss.summarize(article,5)
summary = summary.encode('ascii','ignore')
article_list.append(article)
summary_list.append(summary)
""" All the outputs are written to appropriate files in this part of the code """
for i in range(1,number_of_links):
f2 = open(query + str(i),'w')
f2.write(article_list[i-1] + '\n' + summary_list[i-1])
f2.close()