Python crawls the full set of skins of the king pesticide

Author: toofelix
Source: http://suo.im/6pj3Zp


1. Analyze the website that needs to be crawled

①、Open the official king of glory wallpaper website

② Shortcut key F12, call up the console for packet capture

③、Find the correct link and analyze

④. View the returned data format

⑤, resolve url link

⑥ Check whether the url content is the desired picture, and found that it is actually a thumbnail

⑦, then go to analyze the website, just click on a wallpaper, and view the link in the specified format

⑧、Find the target address###

⑨、Analyze the difference between target link and thumbnail

Two, crawler code#

① At this point, the crawler analysis is complete, and the complete crawler code is as follows###

#! /usr/bin/env python
# encoding: utf-8'''
#-------------------------------------------------------------------
#     CONFIDENTIAL --- CUSTOM STUDIOS
#-------------------------------------------------------------------
#
#     @ Project Name :King of glory wallpaper download
#
#     @ File Name    : main.py
#
#     @ Programmer   : Felix
#
#     @ Start Date   :2020/7/3014:42
#
#     @ Last Update  :2020/7/3014:42
#
#-------------------------------------------------------------------'''
import os, time, requests, json, re
from retrying import retry
from urllib import parse
 
classHonorOfKings:'''
  This is a main Class, the file contains all documents.
  One document contains paragraphs that have several sentences
  It loads the original file and converts the original file to newcontent
  Then the newcontent will be saved by thisclass'''
 def __init__(self, save_path='./heros'):
  self.save_path = save_path
  self.time =str(time.time()).split('.')
  self.url ='https://apps.game.qq.com/cgi-bin/ams/module/ishow/V1.0/query/workList_inc.cgi?activityId=2735&sVerifyCode=ABCD&sDataType=JSON&iListNum=20&totalpage=0&page={}&iOrder=0&iSortNumClose=1&iAMSActivityId=51991&_everyRead=true&iTypeId=2&iFlowId=267733&iActId=2735&iModuleId=2735&_=%s'% self.time[0]
 
 def hello(self):'''
  This is a welcome speech
  : return: self
        '''
  print("*"*50)print(' '*18+'King of glory wallpaper download')print(' '*5+'Author: Felix  Date: 2020-05-20 13:14')print("*"*50)return self
 
 def run(self):'''
  The program entry
        '''
  print('↓'*20+'Format selection: '+'↓'*20)print('1.Thumbnail 2.1024x768 3.1280x720 4.1280x1024 5.1440x900 6.1920x1080 7.1920x1200 8.1920x1440')
  size =input('Please enter the serial number of the format you want to download, the default is 6:')
  size = size if size and int(size)in[1,2,3,4,5,6,7,8]else6print('---Download starts...')
  page =0
  offset =0
  total_response = self.request(self.url.format(page)).text
  total_res = json.loads(total_response)
  total_page =--int(total_res['iTotalPages'])print('---In total{}page...'.format(total_page))while True:if offset > total_page:break
   url = self.url.format(offset)
   response = self.request(url).text
   result = json.loads(response)
   now =0for item in result["List"]:
    now +=1
    hero_name = parse.unquote(item['sProdName']).split('-')[0]
    hero_name = re.sub(r'[【】:.<>|·@#$%^&() ]','', hero_name)print('---Downloading{}page{}Hero progress{}/{}...'.format(offset, hero_name, now,len(result["List"])))
    hero_url = parse.unquote(item['sProdImgNo_{}'.format(str(size))])
    save_path = self.save_path +'/'+ hero_name
    save_name = save_path +'/'+ hero_url.split('/')[-2]if not os.path.exists(save_path):
     os.makedirs(save_path)if not os.path.exists(save_name):withopen(save_name,'wb')as f:
      response_content = self.request(hero_url.replace("/200","/0")).content
      f.write(response_content)
   offset +=1print('---Download completed...')
 
 @ retry(stop_max_attempt_number=3)
 def request(self, url):'''
  Send a request
  : param url: the url of request
  : param timeout: the time of request
  : return: the result of request
        '''
  response = requests.get(url, timeout=10)
  assert response.status_code ==200return response
 
if __name__ =="__main__":HonorOfKings().hello().run()

②, detailed analysis link

self.url ='https://apps.game.qq.com/cgi-bin/ams/module/ishow/V1.0/query/workList_inc.cgi?activityId=2735&sVerifyCode=ABCD&sDataType=JSON&iListNum=20&totalpage=0&page={}&iOrder=0&iSortNumClose=1&iAMSActivityId=51991&_everyRead=true&iTypeId=2&iFlowId=267733&iActId=2735&iModuleId=2735&_=%s'% self.time[0]

③、Format selection###

print('↓'*20+'Format selection: '+'↓'*20)print('1.Thumbnail 2.1024x768 3.1280x720 4.1280x1024 5.1440x900 6.1920x1080 7.1920x1200 8.1920x1440')
size =input('Please enter the serial number of the format you want to download, the default is 6:')
size = size if size and int(size)in[1,2,3,4,5,6,7,8]else6

④, download code analysis

print('---Download starts...')
page =0
offset =0
total_response = self.request(self.url.format(page)).text
total_res = json.loads(total_response)
total_page =--int(total_res['iTotalPages'])print('---In total{}page...'.format(total_page))while True:if offset > total_page:break
 url = self.url.format(offset)
 response = self.request(url).text
 result = json.loads(response)
 now =0for item in result["List"]:
  now +=1
  hero_name = parse.unquote(item['sProdName']).split('-')[0]
  hero_name = re.sub(r'[【】:.<>|·@#$%^&() ]','', hero_name)print('---Downloading{}page{}Hero progress{}/{}...'.format(offset, hero_name, now,len(result["List"])))
  hero_url = parse.unquote(item['sProdImgNo_{}'.format(str(size))])
  save_path = self.save_path +'/'+ hero_name
  save_name = save_path +'/'+ hero_url.split('/')[-2]if not os.path.exists(save_path):
   os.makedirs(save_path)if not os.path.exists(save_name):withopen(save_name,'wb')as f:
    response_content = self.request(hero_url.replace("/200","/0")).content
    f.write(response_content)
 offset +=1print('---Download completed...')

⑤, the results of the crawler running, put the same name in the same folder

< END >

Recommended Posts

Python crawls the full set of skins of the king pesticide
Python crawls a full set of skins for the glory of the king
Consolidate the foundation of Python (4)
Consolidate the foundation of Python(7)
Consolidate the foundation of Python(6)
python king of glory wallpaper
Consolidate the foundation of Python(5)
Consolidate the foundation of Python (3)
The usage of wheel in python
Python simulation of the landlord deal
What is the use of Python
​Full analysis of Python module knowledge
The premise of Python string pooling
Secrets of the new features of Python 3.8
The father of Python joins Microsoft
The operation of python access hdfs
The usage of tuples in python
End the method of running python
Understanding the meaning of rb in python
Learn the basics of python interactive mode
What are the required parameters of python
Logistic regression at the bottom of python
The usage of Ajax in Python3 crawler
Python solves the Tower of Hanoi game
Solve the conflict of multiple versions of python
What is the scope of python variables
Python implements the sum of fractional sequences
Two days of learning the basics of Python
What is the id function of python
Where is the pip path of python3
The essence of Python language: Itertools library
What are the advantages of python language
The specific method of python instantiation object
python3 realizes the function of mask drawing
What is the prospect of python development
What is the function body of python
The specific method of python import library
Solve the conflict of multiple versions of python
What is the function of adb in python
Detailed explanation of the principle of Python super() method
The difference between the syntax of java and python
Python realizes the development of student management system
Python implements the shuffling of the cards in Doudizhu
The meaning and usage of lists in python
Solve the problem of python running startup error
Can the value of the python dictionary be modified?
Python implements the source code of the snake game
Detailed explanation of the usage of Python decimal module
How about learning python at the age of 27?
The consequences of uninstalling python in ubuntu, very
Python writes the game implementation of fishing master