我正在为不同的新闻机构创建一个网页刮板。我试图为The Hindu
报纸创建一个。在
我想从它的档案中提到的各个环节得到新闻。假设我想在第二天的链接上得到新闻:http://www.thehindu.com/archive/web/2010/06/19/
那是2010年6月19日。在
现在我写了以下几行代码:
import mechanize
from bs4 import BeautifulSoup
url = "http://www.thehindu.com/archive/web/2010/06/19/"
br = mechanize.Browser()
htmltext = br.open(url).read()
articletext = ""
soup = BeautifulSoup(htmltext)
for tag in soup.findAll('li', attrs={"data-section":"Business"}):
articletext += tag.contents[0]
print articletext
但我无法得到所需的结果。我基本上被卡住了。有人能帮我解决吗?在
我建议你退房。用你的参数试试他们的教程,然后用它来做实验。他们有一个比机械化模块更发达的网络爬行基础设施。在
请尝试以下代码:
对于
re
,您可能需要导入re
模块。在相关问题 更多 >
编程相关推荐