Created
August 27, 2016 17:05
-
-
Save tatzyr/4a6bf9c08644cfd06f8833fdf4827c00 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# frozen_string_literal: true | |
require "mechanize" | |
require "uri" | |
list_urls = [ | |
"https://www.plusalpha-glass.net/index.php?lang_id=ja&genre_id=&keyword=&sch_goods_tag=&act=&sortkey=&offset=0&tsuka_conv=jpy", | |
"https://www.plusalpha-glass.net/index.php?lang_id=ja&genre_id=&keyword=&sch_goods_tag=&act=&sortkey=&offset=60&tsuka_conv=jpy", | |
"https://www.plusalpha-glass.net/index.php?lang_id=ja&genre_id=&keyword=&sch_goods_tag=&act=&sortkey=&offset=120&tsuka_conv=jpy" | |
] | |
url_and_values = [] | |
agent = Mechanize.new | |
list_urls.each do |list_url| | |
list_page = agent.get(list_url) | |
item_urls = list_page.css(".goodslist_box2 a").map{|x| x.attr("href") }.uniq | |
item_urls.map! {|item_url| URI.join(list_url, item_url).to_s } | |
item_urls.each do |item_url| | |
page = agent.get(item_url) | |
name = page.css("#main_cont2 > div.col-xs-6 > table:nth-child(3) > tr:nth-child(2) > td.cell_d").text.strip | |
price = page.css("#main_cont2 > div.col-xs-6 > table:nth-child(3) > tr:nth-child(3) > td.cell_d").text.strip.sub(",", "").to_i | |
count = page.css("#main_cont2 > div.col-xs-6 > table:nth-child(3) > tr:nth-child(4) > td.cell_d").text.strip.sub(",", "").to_i | |
p [item_url, name, price, count] | |
url_and_values << [item_url, name, price, count] | |
sleep 1 | |
end | |
sleep 1 | |
end | |
puts | |
p url_and_values.sort_by {|*, count| count } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment