require 'json'
require 'http'
require 'nokogiri'
require 'fileutils'
# 伪装自己
headers = {
'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Safari/537.36'
}
hero_list_url = 'https://pvp.qq.com/web201605/js/herolist.json'
resp = HTTP.get(hero_list_url,:headers => headers)
hero_list_json = JSON.parse(resp.body.to_s)
# puts hero_list_json
hero_list_json.each do |h|
ename = h['ename']
cname = h['cname']
FileUtils.mkdir_p(cname) unless File.directory?(cname)
# 访问英雄主页
hero_info_url = "https://pvp.qq.com/web201605/herodetail/#{ename}.shtml"
hero_info_html = HTTP.get(hero_info_url,:headers => headers).body.to_s
doc = Nokogiri::HTML(hero_info_html,nil,'GBK')
names = doc.xpath('//ul[@class="pic-pf-list pic-pf-list3"]/@data-imgname')[0].content
names = names.split('|').map { |name| name[0..name.index('&') - 1] }
# 发送请求
names.each_with_index do |n, i|
skin_url = "http://game.gtimg.cn/images/yxzj/img201606/skin/hero-info/#{ename}/#{ename}-bigskin-#{i + 1}.jpg"
skin_content = HTTP.get(skin_url, :headers=> headers).body.to_s
# 保存图片(皮肤)
File.open("#{cname}/#{n}.jpg", 'wb') do |f|
f.write(skin_content)
end
puts "已下载: #{n} 的皮肤"
sleep(1)
end
end
本文由【产品经理不是经理】gzh 同步发布,欢迎关注