Skip to content

Instantly share code, notes, and snippets.

@SamDarbonne
Last active October 13, 2016 16:04
Show Gist options
  • Select an option

  • Save SamDarbonne/45980743208d2af11b4c81ec00fc426c to your computer and use it in GitHub Desktop.

Select an option

Save SamDarbonne/45980743208d2af11b4c81ec00fc426c to your computer and use it in GitHub Desktop.
What is that nokogiri thing that makes rails take so long to set up?

Nokogiri parses and edits HTML documents. I have not been able to find out why Nokogiri takes to long to gem install but I believe Rails uses it to compile .erb files. You can use Nokogiri to read and modify HTML documents both locally and by grabbing them from URLs.

###This Line grabs the Nokogiri homepage and stores it as a Nokogiri document. Nokogiri documents are special and do many things that we won't go into

doc = Nokogiri::HTML(open('http://www.nokogiri.org/tutorials/installing_nokogiri.html'))
###Let's parse our Nokogiri doc! this searches through the menus in the nav bar of the Nokogiri doc and prints out the content of each h2 tag

doc.css('nav ul.menu li a', 'article h2').each do |link| puts link.content end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment