【发布时间】:2014-09-20 10:01:22
【问题描述】:
我编写了一个脚本,它从文章中提取段落并将它们写入文件。对于某些文章,它不会拉动每一段。这就是我迷路的地方。任何指导将不胜感激。我已经包含了一个特定文章的链接,它没有提取所有信息。它会刮掉所有内容,直到第一个引用的句子。
网址:http://www.reuters.com/article/2014/03/06/us-syria-crisis-assad-insight-idUSBREA250SD20140306
# Ask user to enter URL
url = raw_input("Please enter a valid URL: ")
# Open txt document for output
txt = open('ctp_output.txt', 'w')
# Parse HTML of article
soup = BeautifulSoup(urllib2.urlopen(url).read())
# retrieve all of the paragraph tags
tags = soup('p')
for tag in tags:
txt.write(tag.get_text() + '\n' + '\n')
【问题讨论】:
标签: python html web-scraping html-parsing beautifulsoup