Mat*_*att 67 python web-crawler
我很想写自己的,但我现在没有足够的时间.我已经看过维基百科的开源爬虫列表,但我更喜欢用Python编写的东西.我意识到我可能只是使用维基百科页面上的一个工具并将其包装在Python中.我可能最终会这样做 - 如果有人对这些工具有任何建议,我愿意听到他们的意见.我通过它的网络界面使用了Heritrix,我发现它非常麻烦.我肯定不会为即将推出的项目使用浏览器API.
提前致谢.另外,这是我的第一个问题!
nos*_*klo 44
使用Scrapy.
它是一个基于扭曲的Web爬虫框架.仍处于重大发展阶段,但已经有效.有很多好吃的东西:
通过在返回的HTML上使用XPath选择器提取有关今天在mininova torrent网站中添加的所有torrent文件的信息的示例代码:
class Torrent(ScrapedItem):
pass
class MininovaSpider(CrawlSpider):
domain_name = 'mininova.org'
start_urls = ['http://www.mininova.org/today']
rules = [Rule(RegexLinkExtractor(allow=['/tor/\d+']), 'parse_torrent')]
def parse_torrent(self, response):
x = HtmlXPathSelector(response)
torrent = Torrent()
torrent.url = response.url
torrent.name = x.x("//h1/text()").extract()
torrent.description = x.x("//div[@id='description']").extract()
torrent.size = x.x("//div[@id='info-left']/p[2]/text()[2]").extract()
return [torrent]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
94607 次 |
| 最近记录: |