Skip to main content

Adding XPath support to pyquery

Project description

pyquery_xpath

一个继承于 pyquery 的python库

起因

  • 它没有重写任何 pyquery 的方法,我非常喜欢这个库,认为它在操作 html 方面的各种方法非常简洁
  • 但我习惯于使用 xpath 选择器,pyquery 仅支持 css 选择器和部分伪类选择器
  • 在选择包含某些文本的节点时,总是会选择符合条件的最外层节点
  • 看了 pyquery 部分代码,发现它基于 lxml.etree 模块实现了 html 路径选择,也就是说它原生支持 xpath 选择器,但却没有实现相应的方法,让我很奇怪(也可能很少有像我这样喜欢混搭的人)
  • 于是我为它添加了一个 xpath 方法,仅此而已

使用方式

>>> h = '<a class="foo1"><span class="foo2"><span class="foo3">Hello</span></span></a>'
>>> d = PyQuery(h)
>>> d('a').xpath('.//span[@class="foo2"]')
[<span.foo2>]
>>> d.xpath('//span[@class="foo2"]')('.foo3')
[<span.foo3>]
>>> d.xpath('.//span[@class="foo2"]')('.foo1')
[]

Project details


Release history Release notifications | RSS feed

This version

0.6

Download files

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

Source Distribution

pyquery_xpath-0.6.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyquery_xpath-0.6-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file pyquery_xpath-0.6.tar.gz.

File metadata

  • Download URL: pyquery_xpath-0.6.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.6

File hashes

Hashes for pyquery_xpath-0.6.tar.gz
Algorithm Hash digest
SHA256 dea45e31134ba4b927d9c9841c7fd4f432372006b05d97b305b8b21578c54107
MD5 3a05b9e10538ceb9dfe43b2c0e12e2db
BLAKE2b-256 de713fe1080100db5fa2754d688c9bca985a15453a4ec03443f9c231987a5719

See more details on using hashes here.

File details

Details for the file pyquery_xpath-0.6-py3-none-any.whl.

File metadata

  • Download URL: pyquery_xpath-0.6-py3-none-any.whl
  • Upload date:
  • Size: 3.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.6

File hashes

Hashes for pyquery_xpath-0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 8d3f2fc01cc22fed1393e7ca4d3c70d99a867eb375d3f34ab74f6723d024034d
MD5 d53754baba86709d1e33e7b1a9505fa3
BLAKE2b-256 6d8684dd578896652f9b82365629f2f0b19a094e9f6dd584fa7b02c0a8e02889

See more details on using hashes here.

Supported by

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