###英雄爬虫
import os
import requests
url = 'https://pvp.qq.com/web201605/js/herolist.json'
herolist = requests.get(url) # 获取英雄列表json文件
herolist_json = herolist.json() # 转化为json格式
hero_name = list(map(lambda x: x['cname'], herolist.json())) # 提取英雄的名字
hero_number = list(map(lambda x: x['ename'], herolist.json())) # 提取英雄的编号
# 下载图片
def downloadPic():
i = 0
for j in hero_number:
# 创建文件夹
os.mkdir("E:\\Users\\" + hero_name[i])
# 进入创建好的文件夹
os.chdir("E:\\Users\\" + hero_name[i])
i += 1
for k in range(10):
# 拼接url
onehero_link = 'http://game.gtimg.cn/images/yxzj/img201606/skin/hero-info/' + str(j) + '/' + str(
j) + '-bigskin-' + str(k) + '.jpg'
im = requests.get(onehero_link) # 请求url
if im.status_code == 200:
open(str(k) + '.jpg', 'wb').write(im.content) # 写入文件
downloadPic()
###装备爬虫
import os
import requests
url = 'https://pvp.qq.com/web201605/js/item.json'
item = requests.get(url)
item_json = item.json() # 转化为json格式
item_name = list(map(lambda x: x['item_name'], item.json()))
item_id = list(map(lambda x: x['item_id'], item.json()))
# 下载图片
def downloadPic():
i = 0
for j in item_id:
# 创建文件夹
os.mkdir("E:\\Users\\" + item_name[i])
# 进入创建好的文件夹
os.chdir("E:\\Users\\" + item_name[i])
i += 1
# 拼接url
onehero_link = 'http://game.gtimg.cn/images/yxzj/img201606/itemimg/' + str(j) + '.jpg'
im = requests.get(onehero_link) # 请求url
if im.status_code == 200:
open(str(j) + '.jpg', 'wb').write(im.content) # 写入文件
downloadPic()
###小头像
import os
import requests
url = 'https://pvp.qq.com/web201605/js/herolist.json'
herolist = requests.get(url) # 获取英雄列表json文件
herolist_json = herolist.json() # 转化为json格式
hero_name = list(map(lambda x: x['cname'], herolist.json())) # 提取英雄的名字
hero_number = list(map(lambda x: x['ename'], herolist.json())) # 提取英雄的编号
# 下载图片
def downloadPic():
i = 0
for j in hero_number:
# 创建文件夹
os.mkdir("E:\\Users\\" + hero_name[i])
# 进入创建好的文件夹
os.chdir("E:\\Users\\" + hero_name[i])
i += 1
# 拼接url
onehero_link = 'http://game.gtimg.cn/images/yxzj/img201606/heroimg/' + str(j) + '/' + str(
j) + '.jpg'
im = requests.get(onehero_link) # 请求url
if im.status_code == 200:
open(str(j) + '.jpg', 'wb').write(im.content) # 写入文件
downloadPic()
import requests
import json
from bs4 import BeautifulSoup
headers = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/63.0.3239.26 Safari/537.36 Core/1.63.5958.400 SLBrowser/10.0.3533.400'}
def GetSoup(url):
resp = requests.get(url, headers=headers)
resp.encoding = 'gbk'
soup = BeautifulSoup(resp.text, 'lxml')
return soup
#获取json数据,并解析成存有英雄id与名字的列表[[id,name],[id1,name1].......]
def jsonToHeroInfoList(jsonURL):
resp =requests.get(jsonURL)
jsonData = json.loads(resp.text)
heroInfoList = []
for data in jsonData:
hero_info =[]
hero_info.append(data['ename'])
hero_info.append(data['cname'])
heroInfoList.append(hero_info)
return heroInfoList
Json_url = "https://pvp.qq.com/web201605/js/herolist.json"
heroInfoList = jsonToHeroInfoList(Json_url)
f = open('E:/users/技能简介.txt', 'a')
for heroInfo in heroInfoList:
# Get Id
_id = heroInfo[0]
name = heroInfo[1]
f.write("\n\n"+name+'\n')
# 找技能
url = 'https://pvp.qq.com/web201605/herodetail/%s.shtml' % _id
soup = GetSoup(url)
skillList = soup.find_all('div', class_="show-list")
for skill in skillList:
skill_name = skill.find('b').text
skill_cd = skill.find('span').text
skill_cost = skill.find_all('span')[1].text
skill_desc = skill.find('p', class_="skill-desc").text
if skill_name != "":
f.write(skill_name+'\n')
f.write(skill_cost+'\n')
f.write(skill_cd+'\n')
f.write(skill_desc+'\n')
print(skill_name+'\n')
print(skill_cost)
print(skill_cd)
print(skill_desc)
f.close()