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
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
’
similar error from scite
ruby myrubyNoki.rb
myrubyNoki.rb:17:inblock 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:inblock 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:ineach' from myrubyNoki.rb:15:in
’
Walmart.com: Search Results for “batman”