Skip to content

Instantly share code, notes, and snippets.

@046569
Created May 8, 2017 11:54
Show Gist options
  • Save 046569/01e483094456b39168663386e49ad2aa to your computer and use it in GitHub Desktop.
Save 046569/01e483094456b39168663386e49ad2aa to your computer and use it in GitHub Desktop.
# encoding = UTF-8
require 'rest-client'
require 'nokogiri'
url = 'http://icp.chinaz.com/searchs'
targets = []
result = ''
IO.foreach(ARGV.first) { |s| targets << s.sub("\n", "\r\n") }
data = { urls: targets.join, btn_search: '查询' }
back = RestClient.post(url, URI.encode_www_form(data))
f = Nokogiri::HTML(back)
a = f.xpath('//*[@id="result_table"]').text.split("\r\n")
a.each(&:strip!)
a.delete_if { |s| s == '' }
i = 0
a.each do |s|
i += 1
if (i % 6).zero?
result << "#{s}\r\n"
else
result << "#{s}|"
end
end
puts result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment