James Vance
James Vance

Reputation: 177

Simple Nokogiri not working: undefined method call for "Nokogiri"

I have Ruby and the Nokogiri gem installed. In irb, I try:

require 'nokogiri'
require 'open-uri'

url = 'http://www.amazon.com/The-Pragmatic-Programmer-Journeyman-Master/dp/020161622X/ref=sr_1_1?ie=UTF8&qid=1380758047&sr=8-1&keywords=the+programmatic+programmer'

data = Nokogiri::HTML::(open(url))

puts data

I always get the same error from the "data" variable.

NoMethodError: undefined method 'call' for Nokogiri:Module
  from (irb):5
  from C:/RailsInstaller/Ruby1.9.3/bin/irb:12:in '(main)'

I'm new with programming, so this may be something very obvious. Excuse my ignorance.

Upvotes: 2

Views: 2200

Answers (2)

Ahmed Elkoussy
Ahmed Elkoussy

Reputation: 8568

I had a similar error

NoMethodError: undefined method `call' for []:Nokogiri::XML::NodeSet

But for a different reason, in my case it was due to an extra dot (put by mistake) like this:

  status = data.css.("status font-large").text

Where it was fixed by removing the extra dot after the css as shown below

  status = data.css("status font-large").text

I hope this helps someone else

Upvotes: 1

Alex.Bullard
Alex.Bullard

Reputation: 5563

Try

Nokogiri::HTML.parse(open(url))

or

Nokogiri::HTML(open(url))

Upvotes: 2

Related Questions