Skip to content

html5libvsnokogiri

MIT 97 14 1,220
32.8 million (month) Jul 30 2007 1.1(2020-06-22 23:32:36 ago)
6,248 23 108 MIT
Jul 25 2009 5.8 million (month) 1.19.2(2026-03-19 21:12:43 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.

Nokogiri is a Ruby gem that provides a simple and powerful way to parse and search XML and HTML documents. It is built on top of the underlying C library libxml2, which is known for its speed and reliability.

Nokogiri provides a simple and intuitive API for parsing and searching XML and HTML documents, and it is widely used in the Ruby ecosystem for web scraping and data extraction.

One of the main features of Nokogiri is its ability to search and navigate through XML and HTML documents using a CSS or XPath selectors.

Nokogiri also provides a variety of other features that can simplify the process of working with XML and HTML documents. It can automatically handle character encodings and normalize documents, it can parse and search large documents with low memory usage, and it can validate documents against a DTD or schema.

Highlights


css-selectorsxpathpopular

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) ```
```ruby require 'nokogiri' html_string = 'Page Title

Hello World!

This is a sample webpage.

' # Parse the HTML string doc = Nokogiri::HTML(html_string) # Extract the class attribute of h1 tag using CSS selector h1_class = doc.css("h1")[0]['class'] # or XPath h1_class = doc.xpath("//h1")[0]['class'] puts "H1 class: #{h1_class}" ```

Alternatives / Similar


Was this page helpful?