Skip to content

Instantly share code, notes, and snippets.

@ohta-rh
Created July 27, 2013 04:18
Show Gist options
  • Save ohta-rh/6093690 to your computer and use it in GitHub Desktop.
Save ohta-rh/6093690 to your computer and use it in GitHub Desktop.
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
@sakamoto-rh
Copy link

ruby piyo.rb -u url -k keywordで実行する。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment