Skip to main content

操作更方便的xpath, 使用方法类似于Beautiful Soup4, 但是比他更快速

Project description

操作更方便的xpath

使用方法类似于Beautiful Soup4, 但是比他更快速

import zxpath

zx = zxpath.load('etree对象或者html源码') #加载

find() #查询一个节点, 失败返回None
zx.find('div', class_='content') #参考 .//div[@class="content"][1]
zx.find('div', class_=False) #参考 .//div[not(@class)][1]
zx.find('div', _class_='content') #参考 .//div[not(@class="content")][1]
zx.find('div', class=True, sun_node=False) #参考 ./div[@class][1] sun_node表示是否递归查询孙级节点

find_all() # 查询多个节点, 参数同find, 返回一个列表, 失败返回空列表
zx(*attr, **kw) #同find_all

#_Element对象
node = zx.find('div')

node.id #获取id属性
node.text #获取文本
node.string #获取整个div的所有文本
node.a #获取在这个节点下搜索到的第一个a元素节点
node.html #获取这个节点的html源码
node.find
node.find_all
node(*attr, **kw) #同find_all
node.xpath_one #使用原始xpath代码查询一个节点
node.xpath_all #使用原始xpath代码查询多个节点


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zxpath-1.0.0.tar.gz (4.9 kB view hashes)

Uploaded Source

Built Distribution

zxpath-1.0.0-py3-none-any.whl (17.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page