日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

用Python3Request爬取英雄联盟皮肤、单线程爬取

發(fā)布時間:2025/3/15 python 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 用Python3Request爬取英雄联盟皮肤、单线程爬取 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
""" Hero_LOL 和王者榮耀類似 """ import requests import re import json import os import threadingdef hero(hero_name, hero_num):#統(tǒng)一前戳h_l = "https://ossweb-img.qq.com/images/lol/web201310/skin/big"# 逐一遍歷英雄print(hero_num.__len__())num = 0 # 為了獲取英雄的號碼for i in hero_num:# 逐一遍歷皮膚,此處假定一個英雄最多15個皮膚for sk_num in range(0, 15): # 從第0個皮膚開始hsl = h_l + i + "00" + str(sk_num) + ".jpg"hl = requests.get(hsl)if hl.status_code == 200:filename = "LOL/" + str(hero_name[num]) + str(sk_num) + ".jpg"print("此時正在下載:" + filename+" 這是第"+str(num+1)+"個英雄")with open(filename, "wb") as f:f.write(hl.content)else:breaknum += 1def main():"""#獲取全部英雄數(shù)據(jù):return:"""#JS_urlHero_url = "https://lol.qq.com/biz/hero/champion.js"#User-Agent偽裝瀏覽器標(biāo)識header = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.109 Safari/537.36'}#Get source code(獲取源代碼)response = requests.get(Hero_url,headers = header)#decode 編碼為GBK,方便下方使用正則遍歷response = response.content.decode("GBK")#regex(正則表達(dá)式)reg = """keys":([\s\S]*?),"data"""#預(yù)編譯regex = re.compile(reg,re.IGNORECASE) #第一個參數(shù) 正則表達(dá)式 第二個參數(shù)忽略的意思,忽略大小寫#findall 就是獲取response內(nèi)所有符合規(guī)則的數(shù)據(jù),返回值為listresponse_s = regex.findall(response)#也就是所有符合規(guī)則的數(shù)據(jù)放到了列表里,如果只有一個,那就是list[0]response_s = response_s[0]#通過eval轉(zhuǎn)換為一個dict,具體功能自己查(其實我也沒大懂)res = eval(response_s)#get the keys in the dict(再轉(zhuǎn)換為list)hero_num = list(res.keys()) #Hero_number#get the values in the dict (再轉(zhuǎn)換為list)hero_name = list(res.values())#Hero_name hero(hero_name,hero_num)if __name__ == '__main__':main()

?

轉(zhuǎn)載于:https://www.cnblogs.com/wxzbk/p/10983976.html

總結(jié)

以上是生活随笔為你收集整理的用Python3Request爬取英雄联盟皮肤、单线程爬取的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。