Skip to content

Instantly share code, notes, and snippets.

@ohta-rh
Last active December 20, 2015 07:29
Show Gist options
  • Save ohta-rh/6093716 to your computer and use it in GitHub Desktop.
Save ohta-rh/6093716 to your computer and use it in GitHub Desktop.
require 'net/http'
require 'uri'
#スクリプト仕様
# httpのみ対応
# 検索結果はresult.csvに出力
class Scribe
attr_accessor :url, :keywords
#params
# url: "http://hogehoge"
# keywords: カンマ区切りのstring
def initialize(uri, keywords)
@uri = URI.parse(uri)
@keywords = keywords.split(",")
end
#TODO: sakamoto checkはあとで。
def check
begin
@uri = URI.parse(@uri)
rescue URI::InvalidURIError
raise ArgmentError, "hoge"
end
end
def search
http = Net::HTTP.get(@uri).force_encoding('UTF-8')
result = {}
keywords.each do |keyword|
result[keyword.to_sym] = http.scan(keyword).size.to_s
end
File.open("result.txt", "w") do |f|
result.each do |k, v|
f.puts "#{k.to_s},#{v}"
end
end
end
end
params = $*
uri = params.shift
keywords = params.shift
scribe = Scribe.new(uri, keywords)
scribe.search
@sakamoto-rh
Copy link

params = $*
uri = params.shift
keywords = params.shift
scribe = Scribe.new(uri, keywords)
scribe.search

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