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.yml
pyquery 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
<https://github.com/gawel/pyquery/issues>`_ 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("<html></html>")
>>> d = pq(etree.fromstring("<html></html>"))
>>> 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#hello.hello>]
>>> p = d("#hello")
>>> print(p.html())
Hello world !
>>> p.html("you know <a href='http://python.org/'>Python</a> rocks")
[<p#hello.hello>]
>>> print(p.html())
you know <a href="http://python.org/">Python</a> rocks
>>> print(p.text())
you know Python rocks
You 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')
[<p#hello.hello>]
See http://pyquery.rtfd.org/ for the full documentation
News
====
2.0.1 (2024-08-30)
------------------
- Breaking change: its seems no longer possible to use the html parser with a xml file so its no longer tested
- Drop support for python 3.7
2.0.0 (2022-12-28)
------------------
- Breaking change: inputs starting with ``"http://"`` or ``"https://"`` like
``PyQuery("http://example.com")`` will no longer fetch the contents of the URL.
Users desiring the old behavior should switch to ``PyQuery(url="http://example.com")``.
- Add nextUntil method
- ``.remove()`` no longer inserts a space in place of the removed element
- Fix escaping of top-level element text in ``.html()`` output
- Support (and require) cssselect 1.2+
- Drop support for python 3.5/3.6
1.4.3 (2020-11-21)
------------------
- No longer use a universal wheel
1.4.2 (2020-11-21)
------------------
- Fix exception raised when calling `PyQuery("<textarea></textarea>").text()`
- python2 is no longer supported
1.4.1 (2019-10-26)
------------------
- This is the latest release with py2 support
- Remove py33, py34 support
- web scraping improvements: default timeout and session support
- Add API methods to serialize form-related elements according to spec
- Include HTML markup when querying textarea text/value
1.4.0 (2018-01-11)
------------------
- Refactoring of `.text()` to match firefox behavior.
1.3.0 (2017-10-21)
------------------
- Remove some unmaintained modules: ``pyquery.ajax`` and ``pyquery.rules``
- Code cleanup. No longer use ugly hacks required by python2.6/python3.2.
- Run tests with python3.6 on CI
- Add a ``method`` argument to ``.outer_html()``
1.2.17 (2016-10-14)
-------------------
- ``PyQuery('<input value="">').val()`` is ``''``
- ``PyQuery('<input>').val()`` is ``''``
1.2.16 (2016-10-14)
-------------------
- ``.attr('value', '')`` no longer removes the ``value`` attribute
- ``<input type="checkbox">`` without ``value="..."`` have a ``.val()`` of
``'on'``
- ``<input type="radio">`` without ``value="..."`` have a ``.val()`` of
``'on'``
- ``<select>`` without ``<option selected>`` have the value of their first
``<option>`` (or ``None`` if there are no options)
1.2.15 (2016-10-11)
-------------------
- .val() should never raise
- drop py26 support
- improve .extend() by returning self
1.2.14 (2016-10-10)
-------------------
- fix val() for <textarea> and <select>, to match jQuery behavior
1.2.13 (2016-04-12)
-------------------
- Note explicit support for Python 3.5
1.2.12 (2016-04-12)
-------------------
- make_links_absolute now take care of whitespaces
- added pseudo selector :has()
- add cookies arguments as allowed arguments for requests
1.2.11 (2016-02-02)
-------------------
- Preserve namespaces attribute on PyQuery copies.
- Do not raise an error when the http response code is 2XX
1.2.10 (2016-01-05)
-------------------
- Fixed #118: implemented usage ``lxml.etree.tostring`` within ``outer_html`` method
- Fixed #117: Raise HTTP Error if HTTP status code is not equal to 200
- Fixed #112: make_links_absolute does not apply to form actions
- Fixed #98: contains act like jQuery
1.2.9 (2014-08-22)
------------------
- Support for keyword arguments in PyQuery custom functions
- Fixed #78: items must take care or the parent
- Fixed #65 PyQuery.make_links_absolute() no longer creates 'href' attribute
when it isn't there
- Fixed #19. ``is_()`` was broken.
- Fixed #9. ``.replaceWith(PyQuery element)`` raises error
- Remove official python3.2 support (mostly because of 3rd party semi-deps)
1.2.8 (2013-12-21)
------------------
- Fixed #22: Open by filename fails when file contains invalid xml
- Bug fix in .remove_class()
1.2.7 (2013-12-21)
------------------
- Use pep8 name for methods but keep an alias for camel case method.
Eg: remove_attr and removeAttr works
Fix #57
- .text() now return an empty string instead of None if there is no text node.
Fix #45
- Fixed #23: removeClass adds class attribute to elements which previously
lacked one
1.2.6 (2013-10-11)
------------------
- README_fixt.py was not include in the release. Fix #54.
1.2.5 (2013-10-10)
------------------
- cssselect compat. See https://github.com/SimonSapin/cssselect/pull/22
- tests improvements. no longer require a eth connection.
- fix #55
1.2.4
-----
- Moved to github. So a few files are renamed from .txt to .rst
- Added .xhtml_to_html() and .remove_namespaces()
- Use requests to fetch urls (if available)
- Use restkit's proxy instead of Paste (which will die with py3)
- Allow to open https urls
- python2.5 is no longer supported (may work, but tests are broken)
1.2.3
-----
- Allow to pass this in .filter() callback
- Add .contents() .items()
- Add tox.ini
- Bug fixes: fix #35 #55 #64 #66
1.2.2
-----
- Fix cssselectpatch to match the newer implementation of cssselect. Fixes issue #62, #52 and #59 (Haoyu Bai)
- Fix issue #37 (Caleb Burns)
1.2.1
-----
- Allow to use a custom css translator.
- Fix issue 44: case problem with xml documents
1.2
---
- PyQuery now uses `cssselect <http://pypi.python.org/pypi/cssselect>`_. See issue 43.
- Fix issue 40: forward .html() extra arguments to ``lxml.etree.tostring``
1.1.1
-----
- Minor release. Include test file so you can run tests from the tarball.
1.1
---
- fix issues 30, 31, 32 - py3 improvements / webob 1.2+ support
1.0
---
- fix issues 24
0.7
---
- Python 3 compatible
- Add __unicode__ method
- Add root and encoding attribute
- fix issues 19, 20, 22, 23
0.6.1
------
- Move README.txt at package root
- Add CHANGES.txt and add it to long_description
0.6
----
- Added PyQuery.outerHtml
- Added PyQuery.fn
- Added PyQuery.map
- Change PyQuery.each behavior to reflect jQuery api
Raw data
{
"_id": null,
"home_page": "https://github.com/gawel/pyquery",
"name": "pyquery",
"maintainer": "Gael Pasgrimaud",
"docs_url": "https://pythonhosted.org/pyquery/",
"requires_python": null,
"maintainer_email": "gael@gawel.org",
"keywords": "jquery html xml scraping",
"author": "Olivier Lauzanne",
"author_email": "olauzanne@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/ae/48/79e774ea00b671d08867f06d9258203be81834236c150ac00e942d8fc4db/pyquery-2.0.1.tar.gz",
"platform": null,
"description": "\npyquery: a jquery-like library for python\n=========================================\n\n.. image:: https://github.com/gawel/pyquery/actions/workflows/tox.yml/badge.svg\n :alt: Build Status\n :target: https://github.com/gawel/pyquery/actions/workflows/tox.yml\n\npyquery allows you to make jquery queries on xml documents.\nThe API is as much as possible similar to jquery. pyquery uses lxml for fast\nxml and html manipulation.\n\nThis is not (or at least not yet) a library to produce or interact with\njavascript code. I just liked the jquery API and I missed it in python so I\ntold myself \"Hey let's make jquery in python\". This is the result.\n\nThe `project`_ is being actively developed on a git repository on Github. I\nhave the policy of giving push access to anyone who wants it and then reviewing\nwhat they do. So if you want to contribute just email me.\n\nPlease report bugs on the `github\n<https://github.com/gawel/pyquery/issues>`_ issue\ntracker.\n\n.. _deliverance: http://www.gawel.org/weblog/en/2008/12/skinning-with-pyquery-and-deliverance\n.. _project: https://github.com/gawel/pyquery/\n\n..\n >>> (urlopen, your_url, path_to_html_file) = getfixture('readme_fixt')\n\nQuickstart\n==========\n\nYou can use the PyQuery class to load an xml document from a string, a lxml\ndocument, from a file or from an url::\n\n >>> from pyquery import PyQuery as pq\n >>> from lxml import etree\n >>> import urllib\n >>> d = pq(\"<html></html>\")\n >>> d = pq(etree.fromstring(\"<html></html>\"))\n >>> d = pq(url=your_url)\n >>> d = pq(url=your_url,\n ... opener=lambda url, **kw: urlopen(url).read())\n >>> d = pq(filename=path_to_html_file)\n\nNow d is like the $ in jquery::\n\n >>> d(\"#hello\")\n [<p#hello.hello>]\n >>> p = d(\"#hello\")\n >>> print(p.html())\n Hello world !\n >>> p.html(\"you know <a href='http://python.org/'>Python</a> rocks\")\n [<p#hello.hello>]\n >>> print(p.html())\n you know <a href=\"http://python.org/\">Python</a> rocks\n >>> print(p.text())\n you know Python rocks\n\nYou can use some of the pseudo classes that are available in jQuery but that\nare not standard in css such as :first :last :even :odd :eq :lt :gt :checked\n:selected :file::\n\n >>> d('p:first')\n [<p#hello.hello>]\n\n\n\nSee http://pyquery.rtfd.org/ for the full documentation\n\nNews\n====\n\n2.0.1 (2024-08-30)\n------------------\n\n- Breaking change: its seems no longer possible to use the html parser with a xml file so its no longer tested\n\n- Drop support for python 3.7\n\n2.0.0 (2022-12-28)\n------------------\n\n- Breaking change: inputs starting with ``\"http://\"`` or ``\"https://\"`` like\n ``PyQuery(\"http://example.com\")`` will no longer fetch the contents of the URL.\n Users desiring the old behavior should switch to ``PyQuery(url=\"http://example.com\")``.\n\n- Add nextUntil method\n\n- ``.remove()`` no longer inserts a space in place of the removed element\n\n- Fix escaping of top-level element text in ``.html()`` output\n\n- Support (and require) cssselect 1.2+\n\n- Drop support for python 3.5/3.6\n\n\n1.4.3 (2020-11-21)\n------------------\n\n- No longer use a universal wheel\n\n\n1.4.2 (2020-11-21)\n------------------\n\n- Fix exception raised when calling `PyQuery(\"<textarea></textarea>\").text()`\n\n- python2 is no longer supported\n\n1.4.1 (2019-10-26)\n------------------\n\n- This is the latest release with py2 support\n\n- Remove py33, py34 support\n\n- web scraping improvements: default timeout and session support\n\n- Add API methods to serialize form-related elements according to spec\n\n- Include HTML markup when querying textarea text/value\n\n\n1.4.0 (2018-01-11)\n------------------\n\n- Refactoring of `.text()` to match firefox behavior.\n\n\n1.3.0 (2017-10-21)\n------------------\n\n- Remove some unmaintained modules: ``pyquery.ajax`` and ``pyquery.rules``\n\n- Code cleanup. No longer use ugly hacks required by python2.6/python3.2.\n\n- Run tests with python3.6 on CI\n\n- Add a ``method`` argument to ``.outer_html()``\n\n\n1.2.17 (2016-10-14)\n-------------------\n\n- ``PyQuery('<input value=\"\">').val()`` is ``''``\n- ``PyQuery('<input>').val()`` is ``''``\n\n\n1.2.16 (2016-10-14)\n-------------------\n\n- ``.attr('value', '')`` no longer removes the ``value`` attribute\n\n- ``<input type=\"checkbox\">`` without ``value=\"...\"`` have a ``.val()`` of\n ``'on'``\n\n- ``<input type=\"radio\">`` without ``value=\"...\"`` have a ``.val()`` of\n ``'on'``\n\n- ``<select>`` without ``<option selected>`` have the value of their first\n ``<option>`` (or ``None`` if there are no options)\n\n\n1.2.15 (2016-10-11)\n-------------------\n\n- .val() should never raise\n\n- drop py26 support\n\n- improve .extend() by returning self\n\n\n1.2.14 (2016-10-10)\n-------------------\n\n- fix val() for <textarea> and <select>, to match jQuery behavior\n\n\n1.2.13 (2016-04-12)\n-------------------\n\n- Note explicit support for Python 3.5\n\n1.2.12 (2016-04-12)\n-------------------\n\n- make_links_absolute now take care of whitespaces\n\n- added pseudo selector :has()\n\n- add cookies arguments as allowed arguments for requests\n\n\n1.2.11 (2016-02-02)\n-------------------\n\n- Preserve namespaces attribute on PyQuery copies.\n\n- Do not raise an error when the http response code is 2XX\n\n1.2.10 (2016-01-05)\n-------------------\n\n- Fixed #118: implemented usage ``lxml.etree.tostring`` within ``outer_html`` method\n\n- Fixed #117: Raise HTTP Error if HTTP status code is not equal to 200\n\n- Fixed #112: make_links_absolute does not apply to form actions\n\n- Fixed #98: contains act like jQuery\n\n\n1.2.9 (2014-08-22)\n------------------\n\n- Support for keyword arguments in PyQuery custom functions\n\n- Fixed #78: items must take care or the parent\n\n- Fixed #65 PyQuery.make_links_absolute() no longer creates 'href' attribute\n when it isn't there\n\n- Fixed #19. ``is_()`` was broken.\n\n- Fixed #9. ``.replaceWith(PyQuery element)`` raises error\n\n- Remove official python3.2 support (mostly because of 3rd party semi-deps)\n\n\n1.2.8 (2013-12-21)\n------------------\n\n- Fixed #22: Open by filename fails when file contains invalid xml\n\n- Bug fix in .remove_class()\n\n\n1.2.7 (2013-12-21)\n------------------\n\n- Use pep8 name for methods but keep an alias for camel case method.\n Eg: remove_attr and removeAttr works\n Fix #57\n\n- .text() now return an empty string instead of None if there is no text node.\n Fix #45\n\n- Fixed #23: removeClass adds class attribute to elements which previously\n lacked one\n\n\n1.2.6 (2013-10-11)\n------------------\n\n- README_fixt.py was not include in the release. Fix #54.\n\n\n1.2.5 (2013-10-10)\n------------------\n\n- cssselect compat. See https://github.com/SimonSapin/cssselect/pull/22\n\n- tests improvements. no longer require a eth connection.\n\n- fix #55\n\n1.2.4\n-----\n\n- Moved to github. So a few files are renamed from .txt to .rst\n\n- Added .xhtml_to_html() and .remove_namespaces()\n\n- Use requests to fetch urls (if available)\n\n- Use restkit's proxy instead of Paste (which will die with py3)\n\n- Allow to open https urls\n\n- python2.5 is no longer supported (may work, but tests are broken)\n\n1.2.3\n-----\n\n- Allow to pass this in .filter() callback\n\n- Add .contents() .items()\n\n- Add tox.ini\n\n- Bug fixes: fix #35 #55 #64 #66\n\n1.2.2\n-----\n\n- Fix cssselectpatch to match the newer implementation of cssselect. Fixes issue #62, #52 and #59 (Haoyu Bai)\n\n- Fix issue #37 (Caleb Burns)\n\n1.2.1\n-----\n\n- Allow to use a custom css translator.\n\n- Fix issue 44: case problem with xml documents\n\n1.2\n---\n\n- PyQuery now uses `cssselect <http://pypi.python.org/pypi/cssselect>`_. See issue 43.\n\n- Fix issue 40: forward .html() extra arguments to ``lxml.etree.tostring``\n\n1.1.1\n-----\n\n- Minor release. Include test file so you can run tests from the tarball.\n\n\n1.1\n---\n\n- fix issues 30, 31, 32 - py3 improvements / webob 1.2+ support\n\n\n1.0\n---\n\n- fix issues 24\n\n0.7\n---\n\n- Python 3 compatible\n\n- Add __unicode__ method\n\n- Add root and encoding attribute\n\n- fix issues 19, 20, 22, 23\n\n0.6.1\n------\n\n- Move README.txt at package root\n\n- Add CHANGES.txt and add it to long_description\n\n0.6\n----\n\n- Added PyQuery.outerHtml\n\n- Added PyQuery.fn\n\n- Added PyQuery.map\n\n- Change PyQuery.each behavior to reflect jQuery api\n\n\n\n\n",
"bugtrack_url": null,
"license": "BSD",
"summary": "A jquery-like library for python",
"version": "2.0.1",
"project_urls": {
"Homepage": "https://github.com/gawel/pyquery"
},
"split_keywords": [
"jquery",
"html",
"xml",
"scraping"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "76f55067b48012967ea166b9bd0a015b69e0560e4c6e7c06f28d9bab8f9dd10b",
"md5": "d394bcc2645f16693567ca374f36ef66",
"sha256": "aedfa0bd0eb9afc94b3ddbec8f375a6362b32bc9662f46e3e0d866483f4771b0"
},
"downloads": -1,
"filename": "pyquery-2.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "d394bcc2645f16693567ca374f36ef66",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 22573,
"upload_time": "2024-08-30T08:12:22",
"upload_time_iso_8601": "2024-08-30T08:12:22.586556Z",
"url": "https://files.pythonhosted.org/packages/76/f5/5067b48012967ea166b9bd0a015b69e0560e4c6e7c06f28d9bab8f9dd10b/pyquery-2.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "ae4879e774ea00b671d08867f06d9258203be81834236c150ac00e942d8fc4db",
"md5": "8a165d20082c1c39322816f7b4ae3725",
"sha256": "0194bb2706b12d037db12c51928fe9ebb36b72d9e719565daba5a6c595322faf"
},
"downloads": -1,
"filename": "pyquery-2.0.1.tar.gz",
"has_sig": false,
"md5_digest": "8a165d20082c1c39322816f7b4ae3725",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 44999,
"upload_time": "2024-08-30T08:12:24",
"upload_time_iso_8601": "2024-08-30T08:12:24.289707Z",
"url": "https://files.pythonhosted.org/packages/ae/48/79e774ea00b671d08867f06d9258203be81834236c150ac00e942d8fc4db/pyquery-2.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-30 08:12:24",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "gawel",
"github_project": "pyquery",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "pyquery"
}