Newsletter
Join the Community
Subscribe to our newsletter for the latest news and updates
Pythonic HTML Parsing for Humans™ — full JavaScript support, CSS and XPath selectors, and async.
Requests-HTML is a Python library for HTML parsing and web scraping that builds on the Requests HTTP client, adding JavaScript rendering, CSS and XPath selectors, and async support to make scraping "for Humans".
Requests-HTML is a Python library that takes an HTTP response or a raw HTML string and returns an HTML object you can query with CSS selectors, XPath, and text search. It runs on Python 3.6 and above, is maintained by the PSF on GitHub, and is installed with pipenv install requests-html. Unlike plain Requests, it can execute JavaScript on a page via Chromium and return the fully rendered DOM.
render() method uses Chromium (through pyppeteer) to execute JavaScript and update the page HTML, allowing access to dynamically loaded content.r.html.find('#about', first=True).xpath() method supports XPath queries for elements, e.g. r.html.xpath('/html/body/div[1]/a').AsyncHTMLSession enables concurrent requests via asession.run(), with arender() for async JavaScript rendering..links returns all relative links and .absolute_links returns absolute URLs, excluding anchors.search() method uses a placeholder pattern to extract text snippets from the rendered HTML.render(), and then use CSS selectors to pull values from content that only appears after JavaScript runs.AsyncHTMLSession to request multiple URLs at once and process each response as it completes.HTML(html=doc) directly from a string to inspect links and elements without making a network request.Start by creating an HTMLSession and issuing a GET request. The response's .html attribute gives you a rich object with .find(), .xpath(), .links, and .search(). For JavaScript-rendered content, call .render(), which downloads Chromium into your home directory (e.g. ~/.pyppeteer/) on first run, then executes the page scripts and updates the HTML.
Yes, it is an open-source library available through pip, and the project is hosted under the Python Software Foundation on GitHub.
Only Python 3.6 and above is supported, as stated in the installation instructions.
Use the .absolute_links property on the HTML object, which resolves relative URLs to full URLs. The .links property returns them in their original relative or absolute form.
Yes, AsyncHTMLSession provides an arender() method, and all the same parsing operations work on the returned responses.