快速HTML5CSS选择器。
selectolax的Python项目详细描述
使用Modest engine的快速html5解析器和css选择器。
安装
来自使用pip的pypi:
pip install selectolax
github的开发版本:
git clone --recursive https://github.com/rushter/selectolax
cd selectolax
pip -r requirements_dev.txt
python setup.py install
示例
fromselectolax.parserimportHTMLParserhtml="<div><p id=p1><p id=p2><p id=p3><a>link</a><p id=p4><p id=p5>text<p id=p6></div>"selector="div > :nth-child(2n+1):not(:has(a))"fornodeinHTMLParser(html).css(selector):print(node.attributes,node.text(),node.tag)print(node.parent.tag)print(node.html)
简单基准
- 平均10次从800个google serp页面解析和检索url的实验。
Package | Time | Memory (peak) |
---|---|---|
selectolax | 2.38 sec. | 768.11 MB |
lxml | 18.67 sec. | 769.21 MB |