Created
August 7, 2016 08:38
-
-
Save alea12/3bc7637e4b7226de8bb69ae150d34ac5 to your computer and use it in GitHub Desktop.
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
require 'google_drive' | |
require 'open-uri' | |
require 'nokogiri' | |
session = GoogleDrive::Session.from_config('config.json') | |
ws = session.spreadsheet_by_key('XXXXXXXXXXXXXXXXXXXXXXXXXX').worksheet_by_title('Sheet1') | |
urls = [ | |
'http://hanabi.walkerplus.com/list/ar0313/', | |
'http://hanabi.walkerplus.com/list/ar0313/2.html', | |
'http://hanabi.walkerplus.com/list/ar0313/3.html', | |
'http://hanabi.walkerplus.com/list/ar0314/', | |
'http://hanabi.walkerplus.com/list/ar0314/2.html', | |
'http://hanabi.walkerplus.com/list/ar0314/3.html', | |
'http://hanabi.walkerplus.com/list/ar0314/4.html', | |
'http://hanabi.walkerplus.com/list/ar0312/', | |
'http://hanabi.walkerplus.com/list/ar0312/2.html', | |
'http://hanabi.walkerplus.com/list/ar0312/3.html', | |
'http://hanabi.walkerplus.com/list/ar0312/4.html', | |
'http://hanabi.walkerplus.com/list/ar0312/5.html', | |
'http://hanabi.walkerplus.com/list/ar0311/', | |
'http://hanabi.walkerplus.com/list/ar0311/2.html', | |
'http://hanabi.walkerplus.com/list/ar0311/3.html', | |
'http://hanabi.walkerplus.com/list/ar0310/', | |
'http://hanabi.walkerplus.com/list/ar0310/2.html', | |
'http://hanabi.walkerplus.com/list/ar0309/', | |
'http://hanabi.walkerplus.com/list/ar0309/2.html', | |
'http://hanabi.walkerplus.com/list/ar0308/', | |
'http://hanabi.walkerplus.com/list/ar0308/2.html', | |
] | |
urls.each do |url| | |
doc = Nokogiri::HTML(open(url)) | |
doc.css('ul.list01 a').each do |a| | |
name = a.css('h2').text | |
place = a.css('.search_result_spot_place').text | |
date = a.css('.search_result_date').text.gsub(/(期間:|※期間中複数日開催あり)/, '') | |
fireworks = a.css('.search_result_other_info_uchiage_num').text.gsub('万発', '0000').gsub('千発', '000').gsub(/(約|万|発|打ち上げ数:)/, '').to_f | |
audience = a.css('.search_result_other_info_hitode').text.gsub('万人', '0000').gsub('千人', '000').gsub(/(約|万|人|昨年の人出:)/, '').gsub('非公開', '0').to_f | |
r = ws.num_rows + 1 | |
ws[r, 1] = name | |
ws[r, 2] = place | |
ws[r, 3] = date | |
ws[r, 4] = fireworks | |
ws[r, 5] = audience | |
ws[r, 6] = (fireworks/audience).to_s | |
ws.save | |
end | |
sleep 0.1 | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment