You are not logged in.

#1 2013-11-10 06:19:03

TuxLyn
Member
From: United States
Registered: 2011-10-26
Posts: 283

[SOLVED] Ruby + Nokogiri Error

I have a problem using "nokogiri" package after its installed.

Ruby v2.0.0p247
gem v2.0.3

gem list
*** LOCAL GEMS ***
bigdecimal (1.2.0)
bundler (1.3.5)
charlock_holmes (0.6.9.4)
io-console (0.4.2)
json (1.7.7)
mini_portile (0.5.2)
minitest (4.3.2)
nokogiri (1.6.0)
psych (2.0.0)
rake (0.9.6)
rdoc (4.0.0)
test-unit (2.0.0.0)

This is example code I'm trying to use from tutorial > http://ruby.bastardsbook.com/chapters/html-parsing/

#!/usr/bin/ruby

require 'rubygems'
require 'nokogiri'
require 'open-uri'

page = Nokogiri::HTML(open('http://en.wikipedia.org/wiki/HTML'))
page.css('div#content div#bodyContent table.infobox tr th').each do |el|
   puts el.text
end

This is error I see in terminal:

/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require': cannot load such file -- nokogiri (LoadError)
	from /usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
	from ./scrape.rb:4:in `<main>'

Also have this warning when I run script using sudo:
WARNING: Nokogiri was built against LibXML version 2.8.0, but has dynamically loaded 2.9.1

Last edited by TuxLyn (2013-11-10 07:52:03)


::: Using Arch Linux Since October 25, 2011 :::
::: Tutorials: http://distrogeeks.com/ :::

Offline

#2 2013-11-10 06:26:41

TuxLyn
Member
From: United States
Registered: 2011-10-26
Posts: 283

Re: [SOLVED] Ruby + Nokogiri Error

Alright it looks like the problem was because I've installed this gem as root :-)
I fixed this by running this two commands;

as root I run this command;
# gem uninstall nokogiri

and as regular user I run;
$ gem install nokogiri

I only see warning now > WARNING: Nokogiri was built against LibXML version 2.8.0, but has dynamically loaded 2.9.1


::: Using Arch Linux Since October 25, 2011 :::
::: Tutorials: http://distrogeeks.com/ :::

Offline

#3 2013-11-10 07:52:36

TuxLyn
Member
From: United States
Registered: 2011-10-26
Posts: 283

Re: [SOLVED] Ruby + Nokogiri Error

I've set -W0 to ignore warning ^_^ My first ruby script works big_smile

https://github.com/GoTux/Ruby/blob/master/ver.rb


::: Using Arch Linux Since October 25, 2011 :::
::: Tutorials: http://distrogeeks.com/ :::

Offline

Board footer

Powered by FluxBB