-1
我正在學習Python來製作網頁抓取工具。以下代碼通過幫助很好地工作。那我想知道如何保存結果?你能幫助解決這個問題嗎?如何在網頁抓取後保存結果文本
import nltk
import urllib
import readability
from bs4 import BeautifulSoup
from readability.readability import Document
import mechanize
url = "http://www.nytimes.com/2015/06/02/science/medicines-hidden-roots-in-an-ancient-manuscript.html?ref=science&_r=0"
br = mechanize.Browser()
br.set_handle_robots(False)
br.addheaders = [('User-agent', 'Firefox')]
html = br.open(url).read()
readable_article = Document(html).summary()
readable_title = Document(html).short_title()
soup = BeautifulSoup(readable_article)
final_article = soup.text
links = soup.findAll('img', src=True)
print final_article
output = zip(readable_article,readable_title)
writer = csv.writer(open('newyorktimes.csv', 'wb'))
writer.writerows(final_article)
exit()
謝謝你這麼多!!!!!!!你救了我。 – Steve