Questions tagged [nokogiri]

An HTML, XML, SAX and Reader parser for Ruby with the ability to search documents via XPath or CSS3 selectors… and much more

Nokogiri (鋸) is an HTML, XML, SAX and Reader parser for Ruby. Among Nokogiri’s many features is the ability to search documents via XPath or CSS3 selectors.

See the Nokogiri cheat-sheet for tips using Nokogiri.

A digest of most of the methods documented at nokogiri.org. Reading the source can help, too.

From the Nokogiri readme:

XML is like violence - if it doesn’t solve your problems, you are not using enough of it.

3699 questions
45
votes
2 answers

Using XPath on single node returns elements in all nodes

I am parsing an XML doc that looks something like this: Favorite Poems 123-456 45 Chocolate Desserts 654-098
Sabrina
  • 485
  • 1
  • 5
  • 11
42
votes
2 answers

extract links (URLs), with nokogiri in ruby, from a href html tags?

I want to extract from a webpage all URLs how can I do that with nokogiri? example:
site 1 site 2
gustavgans
  • 5,141
  • 13
  • 41
  • 51
42
votes
3 answers

Nokogiri/Xpath namespace query

I'm trying to pull out the dc:title element using an xpath. I can pull out the metadata using the following code. doc = <
Jamie
  • 2,245
  • 4
  • 19
  • 24
41
votes
6 answers

Getting attribute's value in Nokogiri to extract link URLs

I have a document which look like this: I can't get Nokogiri to get me the value of href attribute. I'd like to store the address in a Ruby variable as a string.
Kreeki
  • 3,662
  • 6
  • 27
  • 33
37
votes
8 answers

Error installing Nokogiri 1.5.0 with rails 3.1.0 and ubuntu

Here is the error running bundle install vendor/gems on server: Installing nokogiri (1.5.0) with native extensions Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension. …
user938363
  • 9,990
  • 38
  • 137
  • 303
35
votes
4 answers

Errors using rspec, missing libraries after installing Homebrew and uninstalling MacPorts

I may have taken one step too far beyond my knowledge. I installed Homebrew and after it continued to give me warnings about having MacPorts installed I uninstalled that. But now my rspec tests don't run. These are the errors I…
markstewie
  • 9,237
  • 10
  • 50
  • 72
34
votes
2 answers

How to prevent Nokogiri from adding tags?

I noticed something strange using Nokogiri recently. All of the HTML I had been parsing had been given start and end and tags.
holden
  • 13,471
  • 22
  • 98
  • 160
34
votes
1 answer

How do I parse an HTML table with Nokogiri?

I installed Ruby and Mechanize. It seems to me that it is posible in Nokogiri to do what I want to do but I do not know how to do it. What about this table? It is just part of the HTML of a vBulletin forum site. I tried to keep the HTML structure…
Radek
  • 13,813
  • 52
  • 161
  • 255
33
votes
17 answers

OS X Lion, Attempting Nokogiri install - libxml2 is missing

sudo gem install nokogiri Building native extensions. This could take a while... ERROR: Error installing nokogiri: ERROR: Failed to build gem native extension. /Users/sajeev86/.rvm/rubies/ruby-1.8.7-p352/bin/ruby extconf.rb checking…
33
votes
7 answers

Error installing Nokogiri on bundle install but already installed

I'm having issues with bundling my Gemfile. I have Nokogiri installed already yet when I run bundle install it fails to load Nokogiri. Installing Nokogiri: gem install nokogiri Building native extensions. This could take a while... Successfully…
T0ny lombardi
  • 1,800
  • 2
  • 18
  • 35
33
votes
5 answers

How to install Nokogiri Ruby gem with mkmf.log saying libiconv not found?

I'm installing the Ruby Nokogiri gem and finding the error below. How to diagnose this and solve it? # gem install nokogiri Building native extensions. This could take a while... ERROR: Error installing nokogiri: ERROR: Failed to build gem native…
joelparkerhenderson
  • 34,808
  • 19
  • 98
  • 119
31
votes
8 answers

How do I pretty-print HTML with Nokogiri?

I wrote a web crawler in Ruby and I'm using Nokogiri::HTML to parse the page. I need to print the page out and while messing around in IRB I noticed a pretty_print method. However it takes a parameter and I can't figure out what it wants. My crawler…
Jarsen
  • 7,432
  • 6
  • 27
  • 26
30
votes
1 answer

Rails Tutorial: nokogiri-1.5.2 error on bundle install

After working through the RVM setup, rspec and guard sections of chapter 3 of the Ruby on Rails Tutorial, whenever I run bundle install I get the following error dump: Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native…
Dan
  • 3,246
  • 1
  • 32
  • 52
29
votes
1 answer

make: /usr/bin/mkdir: Command not found during `gem install nokogiri` in Ubuntu 20.04

I already installed all neccessary libraries it couldn't found (libxslt-dev, libxml2-dev), specified -- --with-xml2-include=/usr/include/libxml2 --use-system-libraries, but it still fails with make "DESTDIR=" install make: /usr/bin/mkdir: Command…
dem1tris
  • 1,012
  • 8
  • 15
29
votes
4 answers

Custom css with kaminari with bootstrap

I try to use paginate with kaminari. My project used bootsrap css, and the result is so ugly:) The html is generated by nokogiri
duykhoa
  • 2,227
  • 1
  • 25
  • 43