以下のコードの結果(puts enname.text含むputs4つ)を何か適当なCSVを作成してそのCSVに出力したいです。
色々、試したのですが、前提知識が不足しているせいかうまくいきません、、、、
申し訳ないのですが、ご教授いただきたいです、、、
sample.csvに入ってるのは以下のURLです
ーーーー
https://www.hareruyamtg.com/ja/purchase/search?product=Kozilek's+Return+foil+OGW&image
https://www.hareruyamtg.com/ja/purchase/searchproduct=Inquisition+of+Kozilek+foil+Magic+Modern+Event+Deck&image
https://www.hareruyamtg.com/ja/purchase/searchproduct=Inquisition+of+Kozilek+foil+ROE&image
ーーーー
ruby
1 2require 'open-uri' 3require 'nokogiri' 4require "csv" 5 6line = [] 7CSV.open("sample.csv", mode = "rt") do |csv| 8 line = csv.readlines 9end 10 11line.each{ |link| 12 for url in link do 13 charset = nil 14 html = open(url) do |f| 15 charset = f.charset 16 f.read 17 end 18 doc = Nokogiri::HTML.parse(html,nil,'utf-8') 19 doc.css('#category_item > div.autopagerize_page_element > ul > li:nth-child(1) > a.itemName').each do |enname| 20 doc.css('#category_item > div.autopagerize_page_element > ul > li:nth-child(2) > a.itemName').each do |jpname| 21 doc.css('#category_item > div.autopagerize_page_element > ul > li:nth-child(1) > div > div.row.not-first.ng-star-inserted > div:nth-child(2)').each do |enprice| 22 doc.css('#category_item > div.autopagerize_page_element > ul > li:nth-child(2) > div > div.row.not-first.ng-star-inserted > div:nth-child(2)').each do |jpprice| 23 24 puts enname.text 25 puts enprice.text 26 puts jpname.text 27 puts jpprice.text 28 end 29 end 30 end 31 end 32 end 33 34 }