Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How python crawled League of Legends's skin picture

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how python crawled League of Legends skin picture related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe everyone after reading this python how to climb League of Legends skin picture article will have a harvest, let's take a look at it.

At first, we always go to the official website of "League of Legends" to find the website of heroes and skin pictures:

URL = r 'https://lol.qq.com/data/info-heros.shtml'

From the above URL you can see that all the heroes are here, press F12 to view the source code, and found that the hero and skin pictures are not given directly, but hidden in the JS file. At this point, you need to click on Network, find the js window, refresh the page, and you will see an option for champion.js. Click to see a dictionary that contains the names of all the heroes and their corresponding numbers.

But only the name of the hero (English) and the corresponding number can not find the picture address, so go back to the web page, casually click on a hero, jump to the page and find pictures of heroes and skin, but to download also need to find the original address, this is the mouse right-click to select "Open in the new tab", the new web page is the original address of the picture.

The red box in the picture is the address of the picture we need. After analysis, we know that the address of each hero and skin is only different (http://ossweb-img.qq.com/images/lol/web201310/skin/big266000.jpg), and the number has 6 digits, the first three represent the hero, and the last three represent the skin. Just found in the js file happens to have the hero's number, and the skin code can be defined by themselves, anyway, each hero skin no more than 20, and then combined on it.

Once the image address is done, you can start to write the program:

The first step: get the js dictionary def path_js (url_js): res_js = requests.get (url_js, verify = False). Content html_js = res_js.decode ("gbk") pat_js = r'"keys": (. *?) "data" 'enc = re.compile (pat_js) list_js = enc.findall (html_js) dict_js = eval (list_js [0]) return dict_js step 2: extract key values from js dictionary to generate url list def path_url (dict_js): pic_list = [] for key in dict_js: for i in range (20): xuhao = str (I) ) if len (xuhao) = = 1: num_houxu = "00" + xuhao elif len (xuhao) = 2: num_houxu = "0" + xuhao numStr = key+num_houxu url = r 'http://ossweb-img.qq.com/images/lol/web201310/skin/big'+numStr+'.jpg' pic_list.append ( Url) print (pic_list) return pic_list step 3: extract the value values from the js dictionary to generate a name list def name_pic (dict_js Path): list_filePath = [] for name in dict_js.values (): for i in range (20): file_path = path + name + str (I) + .jpg 'list_filePath.append (file_path) return list_filePath step 4: download and save data def writing (url_list) List_filePath): try: for i in range (len (url_list)): res = requests.get (url_list [I], verify = False). Content with open (list_filePath [I], "wb") as f: f.write (res) except Exception as e: print ("error downloading picture,% s"% (e)) return False

Execute the main program:

If _ _ name__ = ='_ main__': url_js = r 'http://lol.qq.com/biz/hero/champion.js' path = rascal. The folder where the picture exists dict_js = path_js (url_js) url_list = path_url (dict_js) list_filePath = name_pic (dict_js, path) writing (url_list) List_filePath) this is the end of the article on "how python crawls League of Legends's skin picture". Thank you for reading! I believe you all have a certain understanding of "how python crawls League of Legends skin pictures". If you want to learn more, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report