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
212
votes
3 answers

HTML-parser on Node.js

Is there something like Ruby's nokogiri on nodejs? I mean a user-friendly HTML-parser. I'd seen on Node.js modules page some parsers, but I can't find something pretty and fresh.
asci
  • 2,540
  • 4
  • 16
  • 15
163
votes
33 answers

Why does installing Nokogiri on Mac OS fail with libiconv is missing?

I've been trying to install Nokogiri on Mac OS 10.9.3 and whatever I try, the install fails in the end with the following error message: $ sudo gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.9.1/include/libxml2…
polarblau
  • 17,649
  • 7
  • 63
  • 84
110
votes
30 answers

Error to install Nokogiri on OSX 10.9 Maverick?

I upgraded my OSX (Lion) to Mavericks and I can't install Nokogiri for my projects. I already install XCode 5.0.1, Command Line Tools (using xcode-select --install), and already installed libxml2 from Homebrew and I am still having problems. The…
squiter
  • 5,711
  • 4
  • 24
  • 24
83
votes
16 answers

Mac user and getting WARNING: Nokogiri was built against LibXML version 2.7.8, but has dynamically loaded 2.7.3

I have done all kinds of research and tried many different things. I know this question has been answered many times, but none of the suggested solutions are working for me. After upgrading to Lion I am getting segmentation faults in Ruby. I'm…
Binary Logic
  • 1,529
  • 2
  • 17
  • 19
75
votes
8 answers

Convert a Nokogiri document to a Ruby Hash

Is there an easy way to convert a Nokogiri XML document to a Hash? Something like Rails' Hash.from_xml.
Ivan
  • 97,549
  • 17
  • 50
  • 58
74
votes
9 answers

How to install Nokogiri on Mac OS Sierra 10.12

I'm having troubles installing Nokogiri (1.6.8.1) on Mac OS Sierra 10.12. I tried using brew install libxml2 libxslt and then referencing the install directories using command line options but it didn't help.
Julian Popov
  • 17,401
  • 12
  • 55
  • 81
73
votes
18 answers

nokogiri gem installation error

I know there are a lot of questions about this gem but no answer has worked for me. When I run in SSH gem install nokogiri I get this error: Extracting libxml2-2.8.0.tar.gz into tmp/x86_64-unknown-linux-gnu/ports/libxml2/2.8.0... OK Running patch…
Claudiu Creanga
  • 8,031
  • 10
  • 71
  • 110
70
votes
18 answers

Nokogiri 'Failed to build gem native extension' when I run bundle install

I'm running bundle install and I'm getting this error: Building nokogiri using system libraries. Gem::Ext::BuildError: ERROR: Failed to build gem native extension. /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb…
FabKremer
  • 2,149
  • 2
  • 17
  • 29
69
votes
4 answers

'require': cannot load such file -- 'nokogiri\nokogiri' (LoadError) when running `rails server`

I'm running a clean install of Ruby 2.2.1 on Windows 8.1 with DevKit. After the installation I run: gem install rails rails new testapp cd testapp rails server leaving everything else at default. The process fails at the last line when, instead of…
Shef
  • 1,044
  • 1
  • 12
  • 19
65
votes
2 answers

How do I remove a node with Nokogiri?

How can I remove tags using Nokogiri? I have the following code but it wont work: # str = 'testtfbu' f =…
all jazz
  • 2,007
  • 2
  • 21
  • 37
62
votes
2 answers

How to access attributes using Nokogiri

I have a simple task of accessing the values of some attributes. This is a simple script that uses Nokogiri::XML::Builder to create a simple XML doc. require 'nokogiri' builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml| …
Liz
  • 621
  • 1
  • 5
  • 3
58
votes
15 answers

Error installing nokogiri: Failed to build gem native extension & libiconv is missing (OSX)

I try to clone this repo and run bundle install. The bundle process failed and throw this error: ... Installing nokogiri 1.6.2.1 with native extensions Building nokogiri using packaged libraries. Gem::Ext::BuildError: ERROR: Failed…
Zulhilmi Zainudin
  • 9,017
  • 12
  • 62
  • 98
54
votes
22 answers

Installing Nokogiri on OSX 10.10 Yosemite

I recently upgrade to the 10.10 Yosemite beta, but I'm having trouble getting Nokogiri installed. I'm using RVM and Ruby 1.9.3. I've also followed the steps here and tried following the instructions on Nokogiri's homepage. I've installed libxml2…
gdavis
  • 2,556
  • 1
  • 20
  • 25
52
votes
4 answers

How to select nodes by matching text

If I have a bunch of elements like:

A paragraph

  • Item 1
  • Apple
  • Orange

Is there a built-in method in Nokogiri that would get me all p elements that contain the text "Apple"? (The example element above would…
Zando
  • 5,473
  • 8
  • 30
  • 37
48
votes
8 answers

Error while installing Nokogiri (1.6.7) on El Capitan

One of my developers have updated Nokogiri, and when pulling the updated Gemfile my bundle install fails. ➜ my-project git:(master) bundle install Fetching source index from https://rubygems.org/ Using rake 10.4.2 Using i18n 0.7.0 Using json…
Cjoerg
  • 1,271
  • 3
  • 21
  • 63
1
2 3
99 100