Package: pyquery
pyquery: a jquery-like library for pythonpyquery 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.Theprojectis 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 thegithubissue
tracker.I’ve spent hours maintaining this software, with love.
Please consider tipping if you like it:BTC: 1PruQAwByDndFZ7vTeJhyWefAghaZx9RZgETH: 0xb6418036d8E06c60C4D91c17d72Df6e1e5b15CE6LTC: LY6CdZcDbxnBX9GFBJ45TqVj8NykBBqsmTQuickstartYou 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 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')
[<p#hello.hello>]Seehttp://pyquery.rtfd.org/for the full documentationNews2.0.0 (2022-12-28)Breaking change: inputs starting with"http://"or"https://"likePyQuery("http://example.com")will no longer fetch the contents of the URL.
Users desiring the old behavior should switch toPyQuery(url="http://example.com").Add nextUntil method.remove()no longer inserts a space in place of the removed elementFix escaping of top-level element text in.html()outputSupport (and require) cssselect 1.2+Drop support for python 3.5/3.61.4.3 (2020-11-21)No longer use a universal wheel1.4.2 (2020-11-21)Fix exception raised when callingPyQuery(“<textarea></textarea>”).text()python2 is no longer supported1.4.1 (2019-10-26)This is the latest release with py2 supportRemove py33, py34 supportweb scraping improvements: default timeout and session supportAdd API methods to serialize form-related elements according to specInclude HTML markup when querying textarea text/value1.4.0 (2018-01-11)Refactoring of.text()to match firefox behavior.1.3.0 (2017-10-21)Remove some unmaintained modules:pyquery.ajaxandpyquery.rulesCode cleanup. No longer use ugly hacks required by python2.6/python3.2.Run tests with python3.6 on CIAdd amethodargument to.outer_html()1.2.17 (2016-10-14)PyQuery('<inputvalue="">').val()is''PyQuery('<input>').val()is''1.2.16 (2016-10-14).attr('value','')no longer removes thevalueattribute<inputtype="checkbox">withoutvalue="..."have a.val()of'on'<inputtype="radio">withoutvalue="..."have a.val()of'on'<select>without<option selected>have the value of their first<option>(orNoneif there are no options)1.2.15 (2016-10-11).val() should never raisedrop py26 supportimprove .extend() by returning self1.2.14 (2016-10-10)fix val() for <textarea> and <select>, to match jQuery behavior1.2.13 (2016-04-12)Note explicit support for Python 3.51.2.12 (2016-04-12)make_links_absolute now take care of whitespacesadded pseudo selector :has()add cookies arguments as allowed arguments for requests1.2.11 (2016-02-02)Preserve namespaces attribute on PyQuery copies.Do not raise an error when the http response code is 2XX1.2.10 (2016-01-05)Fixed #118: implemented usagelxml.etree.tostringwithinouter_htmlmethodFixed #117: Raise HTTP Error if HTTP status code is not equal to 200Fixed #112: make_links_absolute does not apply to form actionsFixed #98: contains act like jQuery1.2.9 (2014-08-22)Support for keyword arguments in PyQuery custom functionsFixed #78: items must take care or the parentFixed #65 PyQuery.make_links_absolute() no longer creates ‘href’ attribute
when it isn’t thereFixed #19.is_()was broken.Fixed #9..replaceWith(PyQuery element)raises errorRemove 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 xmlBug 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 #45Fixed #23: removeClass adds class attribute to elements which previously
lacked one1.2.6 (2013-10-11)README_fixt.py was not include in the release. Fix #54.1.2.5 (2013-10-10)cssselect compat. Seehttps://github.com/SimonSapin/cssselect/pull/22tests improvments. no longer require a eth connection.fix #551.2.4Moved to github. So a few files are renamed from .txt to .rstAdded .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 urlspython2.5 is no longer supported (may work, but tests are broken)1.2.3Allow to pass this in .filter() callbackAdd .contents() .items()Add tox.iniBug fixes: fix #35 #55 #64 #661.2.2Fix cssselectpatch to match the newer implementation of cssselect. Fixes issue #62, #52 and #59 (Haoyu Bai)Fix issue #37 (Caleb Burns)1.2.1Allow to use a custom css translator.Fix issue 44: case problem with xml documents1.2PyQuery now usescssselect. See issue 43.Fix issue 40: forward .html() extra arguments tolxml.etree.tostring1.1.1Minor release. Include test file so you can run tests from the tarball.1.1fix issues 30, 31, 32 - py3 improvements / webob 1.2+ support1.0fix issues 240.7Python 3 compatibleAdd __unicode__ methodAdd root and encoding attributefix issues 19, 20, 22, 230.6.1Move README.txt at package rootAdd CHANGES.txt and add it to long_description0.6Added PyQuery.outerHtmlAdded PyQuery.fnAdded PyQuery.mapChange PyQuery.each behavior to reflect jQuery api