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.
Asked
Active
Viewed 1,013 times
4
-
isnt nokogiri crystal compatible? – marmeladze May 07 '17 at 09:48
-
@marmeladze No ruby libraries are "crystal compatible" in the same way you can't use Java libraries from JavaScript, they're entirely different languages. – Stephie May 07 '17 at 12:49
-
https://github.com/veelenga/awesome-crystal#htmlxml-parsing – Vitalii Elenhaupt May 11 '17 at 06:51
-
Yes. Off topic. – user207421 Jan 05 '18 at 09:29
3 Answers
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