Skip to content

Guide · Open source

How to use requests-html: fetch pages and parse HTML in Python

Updated · written with AI from the project's own documentation and checked against our catalogue data

requests-html is a Python library for fetching web pages and pulling information out of their HTML using CSS selectors. It is built on the requests HTTP library, so it will feel familiar if you already use requests. This guide explains what it does, what you need before starting, how it fits next to similar tools, and where it is a poor choice.

requests-htmlpsf/requests-html · ★ 13.8k · MIT

Quick start

  1. 1Check Python is installed. Confirm you have a working Python environment, since Python is the only prerequisite listed.
  2. 2Install the library. Use your Python package manager to install requests-html. The available source does not include the exact command, so check the project homepage.
  3. 3Make a request. Use the requests-style interface to fetch the page you want to read.
  4. 4Parse the HTML. Load the returned HTML so you can query it.
  5. 5Select elements with CSS selectors. Write a CSS selector that matches the element holding the data you want.
  6. 6Extract and check the values. Read the text or attributes from the matched elements and compare them against the page to confirm they are correct.

What requests-html does and who it is for

requests-html is described by its project as Pythonic HTML parsing for humans. It combines fetching a page with parsing its HTML, and lets you select elements with CSS selectors.

Because it is built on top of requests, the way you make HTTP requests will look the same as the requests library you may already know.

  • Python developers who already use requests and want to parse HTML in the same style
  • Small scraping scripts that pull a few fields from pages
  • People learning how web scraping with CSS selectors works

What you need before you install requests-html

The only prerequisite listed in the project source is Python. The source uses a package-manager install method, but the README excerpt available does not include install commands, so check the project's homepage or package listing for the exact install steps.

The project homepage is http://html.python-requests.org and the code is published under the MIT licence.

  • Python installed on your machine
  • A package manager for Python to install the library

Fetch a page and select elements with CSS selectors

The core workflow is to request a page, then query its HTML with CSS selectors to find the elements you need and read their content. This is the same selector idea used by tools such as pyquery and BeautifulSoup, which the project lists as related tools.

The README excerpt available to us was truncated, so it does not show the exact function names or example code. Consult the full documentation at the homepage for working examples before relying on specific calls.

  • Request the page URL using the requests-style interface
  • Parse the returned HTML
  • Select elements with a CSS selector and read their text or attributes

Know the limits before you scrape at scale

requests-html is a good fit for small scripts that pull a few fields from a page. The README excerpt we reviewed gives no performance or concurrency details, so do not assume it handles large crawls well.

The last push shown for the project is not recent, and the README could not confirm its current maintenance status. If you need a dependency that is actively maintained for years, weigh that risk.

  • Large-scale crawling is not covered by the source
  • Long-term maintenance status could not be confirmed from the source

Compare requests-html with similar tools

The project's topics list lxml, pyquery and BeautifulSoup as related tools, and comparable projects include Scrapy. Each sits at a different point on the spectrum between a simple parser and a full crawling framework.

Choose a parser-focused library for a few fields from a page, and consider a full framework like Scrapy when you need crawling, scheduling and scale. The source does not provide benchmarks, so compare them on your own pages.

  • BeautifulSoup: widely used HTML parser
  • pyquery: jQuery-style selectors for Python
  • lxml: fast XML and HTML library
  • Scrapy: full scraping and crawling framework

What people use it for

  • Pulling a few fields such as titles or prices from a single page in a small script
  • Learning how CSS selectors map onto a page's HTML structure
  • Adding HTML parsing to an existing project that already uses requests

Frequently asked questions

Is requests-html free to use?

Yes, the project is published under the MIT licence. Check the licence file in the project repository for the full terms.

What do I need to run requests-html?

The only prerequisite listed in the source is Python. You also need your Python package manager to install the library.

Is requests-html still maintained?

The last push shown in the source is not recent, and the README could not confirm current status. Check the repository's commit history before depending on it for a long-term project.

What is the difference between requests-html and BeautifulSoup?

Both are used to parse HTML in Python, but requests-html is built on requests and combines fetching with parsing. The source does not include a detailed feature comparison, so test both on your target pages.

What are good alternatives to requests-html?

The project lists lxml, pyquery and BeautifulSoup as related tools. For full crawling, Scrapy is a comparable project in the source.

Can I use requests-html for large-scale crawling?

The source gives no performance or concurrency details, so it is not documented for large crawls. For big crawls, consider a framework such as Scrapy.

New agent skills, repos and AI tools — every week

The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.

Our verdict

requests-html suits Python developers who already use requests and want to pull a few fields from pages with CSS selectors. Pick a different tool if you need large-scale crawling or a dependency with confirmed, active maintenance, since the source cannot verify either.

Install options & downloads