Created
June 8, 2013 14:33
-
-
Save yswallow/5735348 to your computer and use it in GitHub Desktop.
AKB総選挙の64位以上の獲得票数の合計を調べる
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
| # coding: UTF-8 | |
| require "open-uri" | |
| require "nokogiri" | |
| url = 'http://akb48matome.com/archives/51881418.html' | |
| page = Nokogiri::HTML(open(url)) | |
| File.write "matome.html" , page.to_html | |
| #page = Nokogiri::HTML(open('./matome.html')) | |
| items = page.xpath('//table/tbody/tr') | |
| sum = 0 | |
| items.each do |item| | |
| str = item.xpath("td[4]").text | |
| hyousu = str.delete(",").to_i | |
| sum += hyousu | |
| end | |
| print sum,"票\n" |
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
| # coding: UTF-8 | |
| require "open-uri" | |
| require "nokogiri" | |
| url = 'http://akb48newstimes.doorblog.jp/archives/28116672.html' | |
| page = Nokogiri::HTML(open(url)) | |
| File.write "matome2.html" , page.to_html | |
| #page = Nokogiri::HTML(open('./matome2.html')) | |
| items = page.xpath('//div[@class="article-body-more"]/div[@class="t_b"][1]') | |
| sum = 0 | |
| html = items.to_html | |
| html.scan(/(\d+)票/).each do |ary| | |
| sum += ary[0].to_i | |
| end | |
| print sum,"票\n" |
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
| # coding: UTF-8 | |
| require "nokogiri" | |
| #require "pp" | |
| page1 = Nokogiri::HTML(open("matome.html")) | |
| page2 = Nokogiri::HTML(open("matome2.html")) | |
| # page2の処理 | |
| items2 = page2.xpath('//div[@class="article-body-more"]/div[@class="t_b"][1]') | |
| html2 = items2.to_html | |
| hyous2 = [] | |
| html2.scan(/(\d+)票/).each do |hyou| | |
| hyous2 << hyou[0].to_i | |
| end | |
| hyous2.sort!.reverse! | |
| # page1の処理 | |
| items1 = page1.xpath('//table/tbody/tr') | |
| sum1 = 0 | |
| hyous1 = [] | |
| items1.each do |item| | |
| str = item.xpath("td[4]").text | |
| hyousu = str.delete(",").to_i | |
| hyous1 << hyousu | |
| end | |
| hyous1.sort!.reverse! | |
| hyous1.delete(0) | |
| 64.times do |i| | |
| print "#{i+1}:\s#{hyous1[i]},#{hyous2[i]}" | |
| puts (hyous1[i] != hyous2[i]) ? "\tdiff!!" : "" | |
| end | |
| print hyous1.inject { |sum,n| sum+n },",",hyous2.inject { |sum,n| sum+n },"\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment