王者榮耀全面板

2021-10-01 23:45:47 字數 2092 閱讀 8185

import os

import time

import requests

herourl = ''

headers =

# 建立目錄檔案

def makedir(x):

# 判斷目錄是否存在,如不存在則建立

if not os.path.exists(x):

os.makedirs(x)

pic = "d:/test/pic"

skin_count_sum = 0

hero_count_sum = 0

starttime = time.time()

try:

response = requests.get(herourl, headers=headers)

json_list = response.json()

hero_count_sum = len(json_list)

for m in range(len(json_list)):

# 編號

ename = json_list[m]['ename']

# 名稱

cname = json_list[m]['cname']

# **數量

skin_count = 0

# 判斷是否有**

if json_list[m].__contains__('skin_name'):

# **列表json

skin_name = json_list[m]['skin_name'].split('|')

# **數量

skin_count = len(skin_name)

# 列印英雄的**數量

print("英雄編號:", ename, ' 英雄名稱:', cname, ' 英雄**數量:', skin_count)

hero_name_pic = pic + "/" + str(ename) + "-" + cname + "-" + str(skin_count) + "/"

makedir(hero_name_pic)

# 遍歷**

for i in range(1, skin_count + 1):

# **拼接, 構造完整的**(可在頁面請求是否有響應)

# url = '' # **固定字首

# 請求獲取資訊

picture = requests.get(url_pic).content

# 寫入檔案

# 列印英雄的**數量

print("英雄編號:", ename, ' 英雄名稱:', cname, ' 英雄**數量:', skin_count)

hero_name_pic = pic + "/" + str(ename) + "-" + cname + "-" + str(skin_count) + "/"

makedir(hero_name_pic)

skin_count_sum += skin_count

except keyerror as e:

print("異常:%s" % e)

print('程式執行完畢')

print("英雄總計:%s" % hero_count_sum)

print("**總計:%s" % skin_count_sum)

endtime = time.time()

print('本次總共耗時 %s s' % round((endtime - starttime), 2))

exit(65536)

說明:在上述herourl請求中獲取的herolist,缺少部分**的資料統計,導致無法獲取全**數量,

如 英雄「馬超」等,需要自己核對具體數值

參考:

爬蟲獲取王者榮耀全英雄面板

coding utf 8 import os,requests,shutil 王者榮耀全英雄 def getherolistinfo url u 獲取到英雄列表資訊 param url return hero name list,hero number list herolist requests....

Python爬蟲 王者榮耀全面板拉取

開門見山,話不多說 英雄資訊列表 import requests import os 英雄資訊列表 hero url 英雄的 字首位址 skin url perfix 當前檔案的絕對路徑 abs path os.path.abspath 獲取所有英雄資訊 head response requests...

python爬蟲 爬取王者榮耀全英雄面板

爬取王者榮耀全英雄 import requests import re 1 分析目標網頁,確定爬取的url路徑,headers引數 base url headers 2 傳送請求 response requests.get base url,headers headers base data res...