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_attributeprice, 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
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'
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_attributeprice, 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
myrubyNoki.rb:17:in `block in <main>': undefined method `text' forruby myrubyNoki.rb
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'