Last active
August 29, 2015 14:03
-
-
Save baboocon/898cd28af5294ff59cc9 to your computer and use it in GitHub Desktop.
新潮文庫の夏の100冊公式サイトから、対象書籍の読書メーターのページURLを取得するスクリプト。
This file contains 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
# -*- coding: utf-8 -*- | |
require 'rubygems' | |
require 'open-uri' | |
id_list = [] | |
bookmeter_100satsu_url = Hash.new | |
open("http://100satsu.com") do |f| | |
f.each_line do |line| | |
if /class=\"book(\d\d\d\d\d\d)\"/ =~ line | |
id_list << $1.to_i | |
end | |
end | |
p id_list | |
p id_list.size | |
title = nil | |
asin = nil | |
id_list.each do |id| | |
list_url = "http://www.shinchosha.co.jp/order/" + "#{id}" | |
open(list_url) do |f| | |
f.each_line do |line| | |
if /<title>(.+)|新潮社<\/title>/ =~ line.force_encoding("UTF-8") | |
title = $1 | |
end | |
if /amazon\.co\.jp\/gp\/product\/(\w\w\w\w\w\w\w\w\w\w)/ =~ line | |
asin = $1 | |
end | |
bookmeter_url = "http://book.akahoshitakuya.com/b/" + "#{asin}" | |
bookmeter_100satsu_url[title] = bookmeter_url | |
end | |
end | |
end | |
end | |
bookmeter_100satsu_url.each do |key, value| | |
if key != nil | |
puts "#{key}, #{value}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment