Life is short, learn Python!

Today is to teach you to use Selenium, one click to crawl LOL hero skin wallpaper.

The first step is to conduct web page analysis

I. Web page analysis

After entering the official website of LOL, hover the mouse over the game materials, wait for the window to appear, select the database, and click enter. You can go directly to 👉lol.qq.com/data/info-h…

Enter the page of all heroes, randomly select a hero to view

A file named hero_list.js contains information about all heroes. You can copy the content to a local TXT file and convert it to JSON using Python.

Import json # with open('hreo_list.txt') as f: Len (rep['hero']) {len(rep['hero'])}") # how many heroes: 152 # https://lol.qq.com/data/info-defail.shtml?id=876 count = 0 for item in rep['hero']: Print (f" ID: {item['heroId']}")Copy the code

Implementation process

Click the hero details page in turn for analysis

Id parameter value is. Js file heroId corresponding to the value of the hero by parameter structure details page URL of the dark woman: https://lol.qq.com/data/info-defail.shtml?id=1 berserker: Justice colossus: https://lol.qq.com/data/info-defail.shtml?id=2 https://lol.qq.com/data/info-defail.shtml?id=3 shy bud: https://lol.qq.com/data/info-defail.shtml?id=876Copy the code

Some heroes have regular skin urls, like Annie’s:

# big + id + 001 JPG from 001 JPG to https://game.gtimg.cn/images/lol/act/img/skin/big1001.jpg https://game.gtimg.cn/images/lol/act/img/skin/big1002.jpg https://game.gtimg.cn/images/lol/act/img/skin/big1003.jpg https://game.gtimg.cn/images/lol/act/img/skin/big1004.jpg https://game.gtimg.cn/images/lol/act/img/skin/big1005.jpgCopy the code

But some, like Parker, have irregular skin urls

https://game.gtimg.cn/images/lol/act/img/skin/big555001.jpg # first https://game.gtimg.cn/images/lol/act/img/skin/big555009.jpg # 2 copies https://game.gtimg.cn/images/lol/act/img/skin/big555016.jpg # 3, 00000000000000Copy the code

In this case, it is not convenient to construct the URL to request the image download. We directly go to Selenium method 👇

Selenium crawler

Crawler dafa good, go 🚀

Partial crawler code, complete code download see the end of the article 👇

Def create_urls(): # open('hreo_list.txt') as f: Con = f.read() # change STR to json rep = json.loads(con) # change STR to json.loads(con) # {len(rep['hero'])}") # https://lol.qq.com/data/info-defail.shtml?id=876 id_ = [] for item in rep['hero']: ID # print (f "heroes: {item} [' heroId] - hero name: {item} [' name ']") id_. Append ((item [' heroId], item [' name '])) return id_Copy the code

The running effect is as follows:

Preview the results

Death is always with me like the wind. Though I have traveled far and wide, I have not lost my heart. A sword’s poor company for a long road

Back then, my Yasuo is also very happy ~

Recently, many friends have sent messages to ask about learning Python. For easy communication, click on blue to join the discussion and answer resource base