Nokogiri & Rb 1.9.2-p0


F

flebber

Is there an error with nokogiri and title recent windows build of ruby
1.9.2-p0?

I have installed ruby and nokogiri gem. I was following the railscast
http://railscasts.com/episodes/190-screen-scraping-with-nokogiri

As I am just learning things I thought I would start by running the
script from the tutorial.

# To change this template, choose Tools | Templates
# and open the template in the editor.

# To change this template, choose Tools | Templates
# and open the template in the editor.

# nokogiri_test.rb
require 'rubygems'
require 'nokogiri'
require 'open-uri'

url = "http://www.walmart.com/search/search-ng.do?
search_constraint=0&ic=48_0&search_query=batman&Find.x=0&Find.y=0&Find=Find"
doc = Nokogiri::HTML(open(url))
puts doc.at_css("title").text
doc.css(".item").each do |item|
title = item.at_css(".prodLink").text
price = item.at_css(".PriceCompare .BodyS, .PriceXLBold").text[/\
$[0-9\.]+/]
puts "#{title} - #{price}"
puts item.at_css(".prodLink")[:href]
end

# lib/tasks/product_prices.rake
desc "Fetch product prices"
task :fetch_prices => :environment do
require 'nokogiri'
require 'open-uri'

Product.find_all_by_price(nil).each do |product|
url = "http://www.walmart.com/search/search-ng.do?
search_constraint=0&ic=48_0&search_query=#{CGI.escape(product.name)}
&Find.x=0&Find.y=0&Find=Find"
doc = Nokogiri::HTML(open(url))
price = doc.at_css(".PriceCompare .BodyS, .PriceXLBold").text[/
[0-9\.]+/]
product.update_attribute:)price, price)
end
end

I keep getting this error.

Walmart.com: Search Results for "batman"
C:/Documents and Settings/Family/My Documents/NetBeansProjects/
RubyApplication3/lib/main.rb:17:in `block in <main>': undefined method
`text' for nil:NilClass (NoMethodError)
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/nokogiri-1.4.3.1-x86-
mingw32/lib/nokogiri/xml/node_set.rb:239:in `block in each'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/nokogiri-1.4.3.1-x86-
mingw32/lib/nokogiri/xml/node_set.rb:238:in `upto'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/nokogiri-1.4.3.1-x86-
mingw32/lib/nokogiri/xml/node_set.rb:238:in `each'
from C:/Documents and Settings/Family/My Documents/
NetBeansProjects/RubyApplication3/lib/main.rb:15:in `<main>'

similar error from scite
ruby myrubyNoki.rb
myrubyNoki.rb:17:in `block in <main>': undefined method `text' for
nil:NilClass (NoMethodError)
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/nokogiri-1.4.3.1-x86-mingw32/
lib/nokogiri/xml/node_set.rb:239:in `block in each'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/nokogiri-1.4.3.1-x86-mingw32/
lib/nokogiri/xml/node_set.rb:238:in `upto'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/nokogiri-1.4.3.1-x86-mingw32/
lib/nokogiri/xml/node_set.rb:238:in `each'
 
Ad

Advertisements

F

flebber

Is there an error with nokogiri and title recent windows build of ruby
1.9.2-p0?

I have installed ruby and nokogiri gem. I was following the railscasthttp://railscasts.com/episodes/190-screen-scraping-with-nokogiri

As I am just learning things I thought I would start by running the
script from the tutorial.

# To change this template, choose Tools | Templates
# and open the template in the editor.

# To change this template, choose Tools | Templates
# and open the template in the editor.

# nokogiri_test.rb
require 'rubygems'
require 'nokogiri'
require 'open-uri'

url = "http://www.walmart.com/search/search-ng.do?
search_constraint=0&ic=48_0&search_query=batman&Find.x=0&Find.y=0&Find=Find "
doc = Nokogiri::HTML(open(url))
puts doc.at_css("title").text
doc.css(".item").each do |item|
  title = item.at_css(".prodLink").text
  price = item.at_css(".PriceCompare .BodyS, .PriceXLBold").text[/\
$[0-9\.]+/]
  puts "#{title} - #{price}"
  puts item.at_css(".prodLink")[:href]
end

# lib/tasks/product_prices.rake
desc "Fetch product prices"
task :fetch_prices => :environment do
  require 'nokogiri'
  require 'open-uri'

  Product.find_all_by_price(nil).each do |product|
    url = "http://www.walmart.com/search/search-ng.do?
search_constraint=0&ic=48_0&search_query=#{CGI.escape(product.name)}
&Find.x=0&Find.y=0&Find=Find"
    doc = Nokogiri::HTML(open(url))
    price = doc.at_css(".PriceCompare .BodyS, .PriceXLBold").text[/
[0-9\.]+/]
    product.update_attribute:)price, price)
  end
end

I keep getting this error.

Walmart.com: Search Results for "batman"
C:/Documents and Settings/Family/My Documents/NetBeansProjects/
RubyApplication3/lib/main.rb:17:in `block in <main>': undefined method
`text' for nil:NilClass (NoMethodError)
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/nokogiri-1.4.3.1-x86-
mingw32/lib/nokogiri/xml/node_set.rb:239:in `block in each'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/nokogiri-1.4.3.1-x86-
mingw32/lib/nokogiri/xml/node_set.rb:238:in `upto'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/nokogiri-1.4.3.1-x86-
mingw32/lib/nokogiri/xml/node_set.rb:238:in `each'
        from C:/Documents and Settings/Family/My Documents/
NetBeansProjects/RubyApplication3/lib/main.rb:15:in `<main>'

similar error from scite
ruby myrubyNoki.rb

myrubyNoki.rb:17:in `block in <main>': undefined method `text' for
nil:NilClass (NoMethodError)
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/nokogiri-1.4.3.1-x86-mingw32/
lib/nokogiri/xml/node_set.rb:239:in `block in each'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/nokogiri-1.4.3.1-x86-mingw32/
lib/nokogiri/xml/node_set.rb:238:in `upto'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/nokogiri-1.4.3.1-x86-mingw32/
lib/nokogiri/xml/node_set.rb:238:in `each'
        from myrubyNoki.rb:15:in `<main>'
Walmart.com: Search Results for "batman"






Exit code: 1

Nobody else having issues with this? Any easy way to fix. I have
updated gems and made sure all dependencies are covered but no go.
Should I go back to 1.9.1 or 1.8.9 ro get compatibility?
 
R

Ryan Davis

Is there an error with nokogiri and title recent windows build of ruby
1.9.2-p0?

You'd be much better off bringing this up on the nokogiri mailing list =
or filing a ticket in their issue tracker. This mailing list is not good =
for specific third party library technical support.
 
F

flebber

You'd be much better off bringing this up on the nokogiri mailing list orfiling a ticket in their issue tracker. This mailing list is not good for specific third party library technical support.

Ah okay because I went back to ruby 1.9.1 and still get same output
error.

ruby nokogiritest.rb
nokogiritest.rb:11:in `block in <main>': undefined method `text' for
nil:NilClass (NoMethodError)
from C:/Ruby191/lib/ruby/gems/1.9.1/gems/nokogiri-1.4.3.1/lib/
nokogiri/xml/node_set.rb:239:in `block in each'
from C:/Ruby191/lib/ruby/gems/1.9.1/gems/nokogiri-1.4.3.1/lib/
nokogiri/xml/node_set.rb:238:in `upto'
from C:/Ruby191/lib/ruby/gems/1.9.1/gems/nokogiri-1.4.3.1/lib/
nokogiri/xml/node_set.rb:238:in `each'
 
Ad

Advertisements

F

flebber

Ah okay because I went back to ruby 1.9.1 and still get same output
error.


nokogiritest.rb:11:in `block in <main>': undefined method `text' for
nil:NilClass (NoMethodError)
        from C:/Ruby191/lib/ruby/gems/1.9.1/gems/nokogiri-1.4.3.1/lib/
nokogiri/xml/node_set.rb:239:in `block in each'
        from C:/Ruby191/lib/ruby/gems/1.9.1/gems/nokogiri-1.4.3.1/lib/
nokogiri/xml/node_set.rb:238:in `upto'
        from C:/Ruby191/lib/ruby/gems/1.9.1/gems/nokogiri-1.4.3.1/lib/
nokogiri/xml/node_set.rb:238:in `each'
        from nokogiritest.rb:9:in `<main>'
Walmart.com: Search Results for "batman"

Actually I have tested on 1.9.2, 1.9.1 & 1.8.7 and didn't work with
railscast script. Must be something I am doing this end, Newbie error.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top