rubyの anemone+nokogiriを用いて
Webスクレイピングをしたいと思っています。
Ruby
1require 'anemone' 2require 'nokogiri' 3require 'kconv' 4 5urls = [] 6urls.push("http://hb-store.com/diet/diet-tea-coffee/item_2791.php") 7 8opts = { 9 :depth_limit => 0, 10 :delay => 1 11} 12 13Anemone.crawl(urls, opts) do |anemone| 14 anemone.on_every_page do |page| 15 doc = Nokogiri::HTML.parse(page.body.toutf8) 16 17 #商品名取得 18 title = doc.xpath("//*[@id='detailItem']/dl/dt").text 19 puts title 20 21 #商品名取得 22 itemename = page.doc.xpath("//*[@class="itemName"]").text 23 puts itemename 24 25 #値段取得 26 itemprice = page.doc.xpath("//*[@class="itemPrice"]").text 27 puts itemprice 28 29 end 30end 31
一番上のtitleの情報は取得できたのですが、
変数、itemename,itempriceの商品名と値段の情報が
以下のエラーが出てしまい取得できないです。
test.rb:22: syntax error, unexpected tIDENTIFIER, expecting ')' itemename = page.doc.xpath("//*[@class="itemName"]").text ^ test.rb:22: syntax error, unexpected ')', expecting keyword_end itemename = page.doc.xpath("//*[@class="itemName"]").text ^ test.rb:26: syntax error, unexpected tIDENTIFIER, expecting ')' itemprice = page.doc.xpath("//*[@class="itemPrice"]").text ^ test.rb:26: syntax error, unexpected ')', expecting keyword_end itemprice = page.doc.xpath("//*[@class="itemPrice"]").text ^
どのように修正したら情報を取得できますでしょうか。
どうぞよろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。