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

2021-10-01 11:20:23 字數 2076 閱讀 9379

# coding=utf-8

import os,requests,shutil

"""王者榮耀全英雄**

"""def getherolistinfo(url=u''):

"""獲取到英雄列表資訊

:param url:

:return:hero_name_list,hero_number_list

"""herolist = requests.get(url) # 獲取英雄列表json檔案

herolist_json = herolist.json() # 轉化為json格式

hero_name_list = list(map(lambda x: x['cname'], herolist.json())) # 提取英雄的名字

hero_number_list = list(map(lambda x: x['ename'], herolist.json())) # 提取英雄的編號

return hero_name_list, hero_number_list

def downloadpic(storagedir="data",

downloadurl=u'',

max_num = 20):

""":param storagedir: 儲存目錄

:param max_num: 最大**種類個數

:return:

"""#記錄當前目錄

current_dir = os.getcwd()

if not os.path.exists(storagedir):

os.mkdir(storagedir)

else:

shutil.rmtree(storagedir)

os.mkdir(storagedir)

print("[info]: 儲存目錄已清空", os.path.join(current_dir,storagedir))

hero_name_list, hero_number_list = getherolistinfo()

print("[info]: 已獲取到英雄列表資訊:\n",

hero_name_list,

hero_number_list)

i = 0

for hero_number in hero_number_list:

hero_name = hero_name_list[i]

print("[info]: 獲取",hero_name,"英雄中...")

#恢復目錄

os.chdir(current_dir)

hero_dir = os.path.join(storagedir, hero_name)

# 建立資料夾

if not os.path.exists(hero_dir):

os.mkdir(hero_dir)

# 進入建立好的資料夾

os.chdir(hero_dir)

i += 1

hero_count = 0

for k in range(max_num):

# 拼接url

im = requests.get(onehero_link) # 請求url

open(picture_name, 'wb').write(im.content) # 寫入檔案

hero_count += 1

print("[info]: 已獲取", hero_name,"個數:",hero_count,"英雄完成...")

os.chdir(current_dir)

if __name__ == '__main__':

downloadpic()

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

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

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

僅供學習參考 import os import requests url herolist requests.get url 獲取英雄列表json檔案 herolist json herolist.json 轉化為json格式 hero name list map lambda x x cname ...

王者榮耀全面板

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 ...