Skip to content

html5libvsdomcrawler

MIT 97 14 1,220
32.8 million (month) Jul 30 2007 1.1(2020-06-22 23:32:36 ago)
4,038 9 - MIT
Sep 26 2011 209.2 thousand (month) v8.0.8(2026-03-30 15:14:47 ago)

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.

DOMCrawler library is part of the Symfony Components project and provides an easy way to traverse and manipulate HTML and XML documents using the Document Object Model (DOM) in PHP.

DOMcrawler supports both CSS selectors and XPath for HTML document parsing and is one the most popular HTML parsing tools used in web scraping with PHP.

Example Use


```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) ```
```javascript use Symfony\Component\DomCrawler\Crawler; $html = '

Hello World

'; $crawler = new Crawler($html); // Find all elements using CSS selectors $elements = $crawler->filter('.title')i; // or XPath $elements = $crawler->filterXPath('//h1'); // Print the text content of the elements foreach ($elements as $element) { echo $element->textContent; } ```

Alternatives / Similar


Was this page helpful?