可配置的python web scraper
scraper的Python项目详细描述
简约的python dom scraper
说明
这个模块是一个易于使用的html/xml刮刀。它同时支持xpath和regular 表达式检索。
一旦有了要从中提取信息的文件,就可以提取 用一个简单的函数调用获得多条信息。
你应该用你自己的方法来获取你想要的文件。
安装
pip install scraper
用法
使用xpath进行scrape:
import scraper import requests content = requests.get('https://github.com/explore').content conf = {'trending-repos' : {'xpath' : '//ol/li/h3/a[2]/@href'}} scraper.scrapes(content, conf) >>> {'trending-repos': ['/jamescryer/grumble.js', '/dominictarr/JSON.sh', '/JamieLottering/DropKick', '/harvesthq/chosen', '/velvia/ScalaStorm']}
使用regexp进行刮擦:
import scraper import requests content = requests.get('http://wiki.nomasnumeros900.com/Air_Liquide').content conf = { 'numbers': {'regexp': '91[\s\d]+', 'transf': [lambda x: x.strip()], 'encoding': 'utf-8'} } scraper.scrapes(content, conf) >>> {'numbers': [u'915 029 300', u'915 029 560', u'915 029 330', u'91']}