欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python通過requests模塊實現(xiàn)抓取王者榮耀全套皮膚

 更新時間:2021年10月29日 15:22:54   作者:小雁子學(xué)Python  
只學(xué)書上的理論是遠(yuǎn)遠(yuǎn)不如實踐帶來的提升快,只有在實例中才能獲得能力的提升,本篇文章手把手帶你用Python實現(xiàn)抓取王者榮耀全套皮膚,大家可以在過程中查缺補漏,提升水平

前言

今天帶大家爬取王者榮耀全套皮膚,廢話不多說,直接開始~

開發(fā)工具

Python版本: 3.6.4

相關(guān)模塊:

requests模塊;

urllib模塊;

以及一些Python自帶的模塊。

環(huán)境搭建

安裝Python并添加到環(huán)境變量,pip安裝需要的相關(guān)模塊即可。

思路分析

1、打開官方王者榮耀壁紙網(wǎng)站
網(wǎng)站地址:https://pvp.qq.com/web201605/wallpaper.shtml

2、快捷鍵F12,調(diào)出控制臺進(jìn)行抓包

抓包

3、找到正確的鏈接并分析

url地址

4、查看返回數(shù)據(jù)格式

在這里插入圖片描述

在這里插入圖片描述

5、解析url鏈接

解析url鏈接

6、查看url內(nèi)容是否是所需圖片,發(fā)現(xiàn)其實是縮略圖

在這里插入圖片描述

7、那就去分析網(wǎng)站,隨便點開一張壁紙,查看指定格式的鏈接

在這里插入圖片描述

8、找到目標(biāo)地址

在這里插入圖片描述

9、分析目標(biāo)鏈接和縮略圖的鏈接區(qū)別
縮略圖:http://shp.qpic.cn/ishow/2735090714/1599460171_84828260_8311_sProdImgNo_6.jpg/200

目標(biāo)圖:http://shp.qpic.cn/ishow/2735090714/1599460171_84828260_8311_sProdImgNo_6.jpg/0

可以知道,將指定格式的縮略圖地址后面200替換成0就是目標(biāo)真實圖片

代碼實現(xiàn)

import os, time, requests, json, re
from retrying import retry
from urllib import parse
 
class HonorOfKings:
    '''
     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 new content
     Then the new content will be saved by this class
    '''
    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 + '王者榮耀壁紙下載')
        print(' ' * 5 + '作者: Felix  Date: 2020-05-20 13:14')
        print("*" * 50)
        return self
 
    def run(self):
        '''
        The program entry
        '''
        print('↓' * 20 + ' 格式選擇: ' + '↓' * 20)
        print('1.縮略圖 2.1024x768 3.1280x720 4.1280x1024 5.1440x900 6.1920x1080 7.1920x1200 8.1920x1440')
        size = input('請輸入您想下載的格式序號,默認(rèn)6:')
        size = size if size and int(size) in [1,2,3,4,5,6,7,8] else 6
 
        print('---下載開始...')
        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('---總共 {} 頁...' . 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 = 0
            for item in result["List"]:
                now += 1
                hero_name = parse.unquote(item['sProdName']).split('-')[0]
                hero_name = re.sub(r'[【】:.<>|·@#$%^&() ]', '', hero_name)
                print('---正在下載第 {} 頁 {} 英雄 進(jìn)度{}/{}...' . 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):
                    with open(save_name, 'wb') as f:
                        response_content = self.request(hero_url.replace("/200", "/0")).content
                        f.write(response_content)
            offset += 1
        print('---下載完成...')
 
    @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 == 200
        return response
 
if __name__ == "__main__":
    HonorOfKings().hello().run()

本期完整源代碼可以私信獲取

代碼運行結(jié)果

pycharm運行

皮膚

到此這篇關(guān)于Python通過requests模塊實現(xiàn)抓取王者榮耀全套皮膚的文章就介紹到這了,更多相關(guān)Python 抓取王者榮耀皮膚內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Django框架教程之中間件MiddleWare淺析

    Django框架教程之中間件MiddleWare淺析

    這篇文章主要給大家介紹了關(guān)于Django框架教程之中間件MiddleWare的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用Django框架具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-12-12
  • Python3.6中Twisted模塊安裝的問題與解決

    Python3.6中Twisted模塊安裝的問題與解決

    這篇文章主要介紹了Python3.6中Twisted模塊安裝的問題與解決,文中通過示例代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用Python具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-04-04
  • Python中的各種裝飾器解析

    Python中的各種裝飾器解析

    這篇文章主要介紹了Python中的各種裝飾器解析,Python裝飾器可以在不改變函數(shù)原實現(xiàn)方式的前提下,為函數(shù)添加額外的功能,需要的朋友可以參考下
    2023-11-11
  • python字符串的常用操作方法小結(jié)

    python字符串的常用操作方法小結(jié)

    這篇文章主要為大家詳細(xì)介紹了python字符串的常用操作方法,如字符串的替換、刪除、截取、復(fù)制、連接、比較、查找、分割等,需要的朋友可以參考下
    2016-05-05
  • 教你學(xué)會使用Python正則表達(dá)式

    教你學(xué)會使用Python正則表達(dá)式

    正則表達(dá)式是一個特殊的字符序列,它能幫助你方便的檢查一個字符串是否與某種模式匹配。 Python 自1.5版本起增加了re 模塊,它提供 Perl 風(fēng)格的正則表達(dá)式模式。re 模塊使 Python 語言擁有全部的正則表達(dá)式功能。
    2017-09-09
  • Python 格式化輸出_String Formatting_控制小數(shù)點位數(shù)的實例詳解

    Python 格式化輸出_String Formatting_控制小數(shù)點位數(shù)的實例詳解

    在本篇文章里小編給大家整理了關(guān)于Python 格式化輸出_String Formatting_控制小數(shù)點位數(shù)的實例內(nèi)容,需要的朋友們參考下。
    2020-02-02
  • python實現(xiàn)感知器算法詳解

    python實現(xiàn)感知器算法詳解

    這篇文章主要為大家詳細(xì)介紹了python實現(xiàn)感知器算法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-12-12
  • 一篇文章徹底搞懂Python類屬性和方法的調(diào)用

    一篇文章徹底搞懂Python類屬性和方法的調(diào)用

    對python?調(diào)用類屬性的方法詳解測試時候類的調(diào)用是經(jīng)常會用到的,下面這篇文章主要給大家介紹了關(guān)于Python類屬性和方法的調(diào)用的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-06-06
  • 最新評論