An HTML parser library for Crystal like the amazing Nokogiri Ruby gem.

I won't pretend that Crystagiri does much as Nokogiri. All help is welcome! :)


Add this to your application's shard.yml:

    github: madeindjs/crystagiri

and then run

$ crystal deps


require "crystagiri"

Then you can simply instantiate a Crystagiri::HTML object from an HTML String like this

doc = "<h1>Crystagiri is awesome!!</h1>"

... or directly load it from a Web URL or a pathname:

doc = Crystagiri::HTML.from_file ""
doc = Crystagiri::HTML.from_url ""
Also you can specify follow: true flag if you want to follow redirect URL

Then you can search all XML::Nodes from the Crystagiri::HTML instance. The tags found will be Crystagiri::Tag objects with the .node property:

puts doc.css("li > strong.title") { |tag| puts tag.node}
# => <strong class="title"> .. </strong>
# => <strong class="title"> .. </strong>
Known limitations: Currently, you can't use CSS queries with complex search specifiers like :nth-child
doc.where_tag("h2") { |tag| puts tag.content }
# => Development
# => Contributing
puts doc.at_id("main-content").tagname
# => div
doc.where_class("summary") { |tag| puts tag.node }
# => <div class="summary"> .. </div>
# => <div class="summary"> .. </div>
# => <div class="summary"> .. </div>


I know you love benchmarks between Ruby & Crystal, so here's one:

require "nokogiri"
t1 =
doc = Nokogiri::HTML"spec/fixture/HTML.html")
1..100000.times do
  doc.css(".step-title"){ |tag| tag }
puts "executed in #{ - t1} milliseconds"
executed in 00:00:11.10 seconds with Ruby 2.6.0 with RVM on old Mac
require "crystagiri"
t =
doc = Crystagiri::HTML.from_file "./spec/fixture/HTML.html"
1..100000.times do
  doc.css(".step-title") { |tag| tag }
puts "executed in #{ - t} milliseconds"
executed in 00:00:03.09 seconds on Crystal 0.27.2 on LLVM 6.0.1 with release flag

Crystagiri is more than two time faster than Nokogiri!!


Clone this repository and navigate to it:

$ git clone
$ cd crystagiri

You can generate all documentation with

$ crystal doc

And run spec tests to ensure everything works correctly

$ crystal spec


  1. Fork it ( )
  2. Create your feature branch git checkout -b my-new-feature
  3. Commit your changes git commit -am "Add some feature"
  4. Push to the branch git push origin my-new-feature
  5. Create a new Pull Request


See the list on Github