Skip to content


NOASSERTION 55 5 2,279
2.2 million (month) Dec 05 2008 2.0.0(1 year, 6 months ago)
13,615 2 222 MIT
Feb 25 2018 1.1 million (month) 0.10.0(5 years ago)

PyQuery is a Python library for working with XML and HTML documents. It is similar to BeautifulSoup and is often used as a drop-in replacement for it.

PyQuery is inspired by javascript's jQuery and uses similar API allowing selecting of HTML nodes through CSS selectors. This makes it easy for developers who are already familiar with jQuery to use PyQuery in Python.

Unlike jQuery, PyQuery doesn't support XPath selectors and relies entirely on CSS selectors though offers similar HTML parsing features like selection of HTML elements, their attributes and text as well as html tree modification.

PyQuery also comes with a http client (through requests) so it can load and parse web URLs by itself.

requests-html is a Python package that allows you to easily make HTTP requests and parse the HTML content of web pages. It is built on top of the popular requests package and uses the html parser from the lxml library, which makes it fast and efficient. This package is designed to provide a simple and convenient API for web scraping, and it supports features such as JavaScript rendering, CSS selectors, and form submissions.

It also offers a lot of functionalities such as cookie, session, and proxy support, which makes it an easy-to-use package for web scraping and web automation tasks.

In short requests-html offers:

  • Full JavaScript support!
  • CSS Selectors (a.k.a jQuery-style, thanks to PyQuery).
  • XPath Selectors, for the faint of heart.
  • Mocked user-agent (like a real web browser).
  • Automatic following of redirects.
  • Connection–pooling and cookie persistence.
  • The Requests experience you know and love, with magical parsing abilities.
  • Async Support



Example Use

from pyquery import PyQuery as pq

# this is our HTML page:
html = """
  <title>Hello World!</title>
  <div id="product">
    <h1>Product Title</h1>
    <p>paragraph 1</p>
    <span class="price">$10</span>

doc = pq(html)

# we can use CSS selectors:
print(doc('#product .price').text())

# it's also possible to modify HTML tree in various ways:
# insert text into selected element:
"<h1>Product Title<span>discounted</span></h1>"

# or remove elements
<h1>Product Title<span>discounted</span></h1>
<span class="price">$10</span>

# pyquery can also retrieve web documents using requests:
doc = pq(url='', headers={"User-Agent": ""})
from requests_html import HTMLSession

session = HTMLSession()
r = session.get('')

# print the HTML content of the page

# use CSS selectors to find specific elements on the page
title = r.html.find('title', first=True)

Alternatives / Similar

Was this page helpful?