Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dsc/pyquery
A jQuery-like library for Python (fork of https://bitbucket.org/olauzanne/pyquery/)
https://github.com/dsc/pyquery
Last synced: about 2 months ago
JSON representation
A jQuery-like library for Python (fork of https://bitbucket.org/olauzanne/pyquery/)
- Host: GitHub
- URL: https://github.com/dsc/pyquery
- Owner: dsc
- License: other
- Created: 2011-08-29T14:03:10.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2011-10-01T12:51:32.000Z (about 13 years ago)
- Last Synced: 2024-10-20T13:50:38.730Z (about 2 months ago)
- Language: Python
- Homepage:
- Size: 122 KB
- Stars: 105
- Watchers: 5
- Forks: 7
- Open Issues: 4
-
Metadata Files:
- Readme: README
- Changelog: CHANGES.txt
- License: LICENSE.txt
Awesome Lists containing this project
README
# PyQuery: a jQuery-like library for Python
PyQuery allows you to make [jQuery](http://jquery.com)-style CSS-selector queries on XML/HTML
documents. The API is intended to match [jQuery's API](http://api.jquery.com) whenever possible,
though it has been made more Pythonic where appropriate.This [project](https://github.com/dsc/pyquery) is a fork of the [original](http://www.bitbucket.org/olauzanne/pyquery)
PyQuery developed by Olivier Lauzanne in 2008; it is maintained by [David Schoonover](mailto:[email protected]). Feedback and bug
reports are both very welcome over on [github](https://github.com/dsc/pyquery/issues).## Quickstart
You can use the PyQuery class to load an xml document from a string, a lxml
document, from a file or from an url:>>> from pyquery import PyQuery as pq
>>> from lxml import etree
>>> import urllib
>>> d = pq("")
>>> d = pq(etree.fromstring(""))
>>> d = pq(url='http://google.com/')
>>> # d = pq(url='http://google.com/', opener=lambda url: urllib.urlopen(url).read())
>>> d = pq(filename=path_to_html_file)Now `d` is like the `$` object in jQuery:
>>> d("#hello")
[]
>>> p = d("#hello")
>>> print(p.html())
Hello world !
>>> p.html("you know Python rocks")
[]
>>> print(p.html())
you know Python rocks
>>> print(p.text())
you know Python rocksYou can use some of the pseudo classes that are available in jQuery but that
are not standard in css such as `:first`, `:last`, `:even`, `:odd`, `:eq`,
`:lt`, `:gt`, `:checked`, `:selected`, and `:file`.>>> d('p:first')
[]
## Notes
* PyQuery uses lxml for fast XML and HTML manipulation.
* This is not a library to produce or interact with JavaScript code. If
that's what you need, check out