Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gawel/pyquery
A jquery-like library for python
https://github.com/gawel/pyquery
css jquery lxml python python3
Last synced: 5 days ago
JSON representation
A jquery-like library for python
- Host: GitHub
- URL: https://github.com/gawel/pyquery
- Owner: gawel
- License: other
- Created: 2012-11-28T20:27:39.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2024-04-02T20:31:58.000Z (7 months ago)
- Last Synced: 2024-05-11T05:41:30.530Z (6 months ago)
- Topics: css, jquery, lxml, python, python3
- Language: Python
- Homepage: http://pyquery.rtfd.org/
- Size: 452 KB
- Stars: 2,272
- Watchers: 65
- Forks: 181
- Open Issues: 55
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGES.rst
- License: LICENSE.txt
Awesome Lists containing this project
- favorite-link - 一个类似 jquery 的 python 库。
- awesome-python-resources - GitHub - 26% open · ⏱️ 17.07.2022): (HTML 处理)
- starred-awesome - pyquery - A jquery-like library for python (Python)
- best-of-web-python - GitHub - 29% open · ⏱️ 02.04.2024): (HTML Processing)
README
pyquery: a jquery-like library for python
=========================================.. image:: https://github.com/gawel/pyquery/actions/workflows/tox.yml/badge.svg
:alt: Build Status
:target: https://github.com/gawel/pyquery/actions/workflows/tox.ymlpyquery allows you to make jquery queries on xml documents.
The API is as much as possible similar to jquery. pyquery uses lxml for fast
xml and html manipulation.This is not (or at least not yet) a library to produce or interact with
javascript code. I just liked the jquery API and I missed it in python so I
told myself "Hey let's make jquery in python". This is the result.The `project`_ is being actively developed on a git repository on Github. I
have the policy of giving push access to anyone who wants it and then reviewing
what they do. So if you want to contribute just email me.Please report bugs on the `github
`_ issue
tracker... _deliverance: http://www.gawel.org/weblog/en/2008/12/skinning-with-pyquery-and-deliverance
.. _project: https://github.com/gawel/pyquery/..
>>> (urlopen, your_url, path_to_html_file) = getfixture('readme_fixt')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=your_url)
>>> d = pq(url=your_url,
... opener=lambda url, **kw: urlopen(url).read())
>>> d = pq(filename=path_to_html_file)Now d is like the $ 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 :file::>>> d('p:first')
[]