Created
July 27, 2013 04:18
-
-
Save ohta-rh/6093690 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
require 'net/http' | |
require 'uri' | |
require 'optparse' | |
require "csv" | |
params = ARGV.getopts("k:", "u:") | |
uri = URI.parse params["u"] | |
document = Net::HTTP.start(uri.host, uri.port) do |http| | |
response = http.get("/") | |
response.body | |
end | |
res = [].tap do |res| | |
res << ["keyword", "count"] | |
params["k"].split(",").each do |keyword| | |
res << [keyword, document.force_encoding("utf-8").scan(/#{keyword}/).size] | |
end | |
end | |
path = %(#{uri.host}.csv) | |
CSV.open(path, "w") do |csv| | |
res.each{|row| csv << row } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ruby piyo.rb -u url -k keywordで実行する。