4

Hey i'm looking for some html parsing libraries in crystal. Something similar to nokogiri for ruby. I have a working regular expression but would prefer a html parsing library because html + regex == bad. Thanks.

Sag0Sag0
  • 95
  • 8

3 Answers3

4

The standard way in the Crystal standard library is XML.parse_html. This will give you an XML::Node which has a pretty nice interface.

If you need to use CSS selectors, you can use Crystagiri, although otherwise I don't see much benefit over the stdlib's offering.

Stephie
  • 3,135
  • 17
  • 22
3

After several hours of googling i just found out about myhtml, modest and Crystagiri. All of them are HTML parsing libraries.

Sag0Sag0
  • 95
  • 8
1

I am the creator of Crystagiri. This is an HTML parser library for Crystal (like the amazing Nokogiri Ruby gem. I won't pretend that Crystagiri does much as Nokogiri but you can use to use CSS selector.

Bellow a basic example:

require "crystagiri"

doc = Crystagiri::HTML.from_url "http://example.com/"
puts doc.css("li > strong.title") { |tag| puts tag.node}
# => <strong class="title"> .. </strong>
# => <strong class="title"> .. </strong>

Thanks to Crystal Lang, Crystagiri is three time faster than Nokogiri (accroding to my test).

alexandre-rousseau
  • 2,321
  • 26
  • 33