require 'net/http'
require 'nokogiri'
require 'benchmark'
begin_time = Time.now
uri = URI('http://www2.kugou.kugou.com/yueku/v8/album/index/getData.js')
referrer_policy="http://www2.kugou.kugou.com"
number = 1
(1..200).each { |i|
params = { :cdn => "cdn", :l => 1, :p => i, :c => 0 }
uri.query = URI.encode_www_form(params)
res = Net::HTTP.get_response(uri)
parsed_data = Nokogiri::HTML.parse(res.body)
if parsed_data.xpath("/html/body//ul//li//a[@class='pic']/@title[1]")[0]==nil then puts "暂无"; break end
title_name = parsed_data.xpath("/html/body//ul//li//a[@class='pic']/@title[1]")
title_name_url = parsed_data.xpath("/html/body//ul//li//a[@class='pic']/@href ")
(0..title_name_url.length - 1).each { |i|
puts "ID:#{number}"
puts title_name[i]
puts Nokogiri::HTML.parse(Net::HTTP.get(URI(referrer_policy + title_name_url[i]))).xpath("/html/body//div[@class='intro']//tr//td/a[@onclick=\"LogStat(1,'','演唱者点击量');\"]/text()")
puts Nokogiri::HTML.parse(Net::HTTP.get(URI(referrer_policy + title_name_url[i]))).xpath("/html/body//div[@class='intro']//tr//td[@id='language']/text()")
puts Nokogiri::HTML.parse(Net::HTTP.get(URI(referrer_policy + title_name_url[i]))).xpath("/html/body//div[@class='intro']//tr//td[@id='company']/text()")
puts Nokogiri::HTML.parse(Net::HTTP.get(URI(referrer_policy + title_name_url[i]))).xpath("/html/body//div[@class='intro']//tr//td[@id='publish_time']/text()")
number=number+1
puts "--------------------------"
}
}
end_time = Time.now
puts "Time taken is #{end_time - begin_time}."