Skip to content

requests-htmlvshtml5lib

MIT 240 2 13,863
720.8 thousand (month) Feb 25 2018 0.10.0(2019-02-17 20:14:17 ago)
1,220 14 97 MIT
Jul 30 2007 32.8 million (month) 1.1(2020-06-22 23:32:36 ago)

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

html5lib is a pure-python library for parsing HTML. It is designed to conform to the WHATWG HTML specification, as is implemented by all major web browsers.

As html5lib is implemented in pure-python it is significantly slower than alternatives powered by lxml (like parsel or beautifulsoup). However, html5lib implements a more true html5 parsing which can represent HTML tree more correctly than alternatives.

Example Use


```python from requests_html import HTMLSession session = HTMLSession() r = session.get('https://www.example.com') # print the HTML content of the page print(r.html.html) # use CSS selectors to find specific elements on the page title = r.html.find('title', first=True) print(title.text) ```
```python import html5lib from html5lib import parse html_doc = "My Title" parsed = parse(html_doc) title = parsed.getElementsByTagName("title")[0] print(title.childNodes[0].nodeValue) ```

Alternatives / Similar


Was this page helpful?