国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

腳本之家,腳本語言編程技術及教程分享平臺!
分類導航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服務器之家 - 腳本之家 - Python - Python通過requests模塊實現抓取王者榮耀全套皮膚

Python通過requests模塊實現抓取王者榮耀全套皮膚

2022-02-21 00:12小雁子學Python Python

只學書上的理論是遠遠不如實踐帶來的提升快,只有在實例中才能獲得能力的提升,本篇文章手把手帶你用Python實現抓取王者榮耀全套皮膚,大家可以在過程中查缺補漏,提升水平

前言

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

 

開發工具

Python版本: 3.6.4

相關模塊:

requests模塊;

urllib模塊;

以及一些Python自帶的模塊。

 

環境搭建

安裝Python并添加到環境變量,pip安裝需要的相關模塊即可。

 

思路分析

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

2、快捷鍵F12,調出控制臺進行抓包

Python通過requests模塊實現抓取王者榮耀全套皮膚

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

Python通過requests模塊實現抓取王者榮耀全套皮膚

4、查看返回數據格式

Python通過requests模塊實現抓取王者榮耀全套皮膚

Python通過requests模塊實現抓取王者榮耀全套皮膚

5、解析url鏈接

Python通過requests模塊實現抓取王者榮耀全套皮膚

6、查看url內容是否是所需圖片,發現其實是縮略圖

Python通過requests模塊實現抓取王者榮耀全套皮膚

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

Python通過requests模塊實現抓取王者榮耀全套皮膚

8、找到目標地址

Python通過requests模塊實現抓取王者榮耀全套皮膚

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

目標圖:http://shp.qpic.cn/ishow/2735090714/1599460171_84828260_8311_sProdImgNo_6.jpg/0

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

 

代碼實現

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("請輸入您想下載的格式序號,默認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("---正在下載第 {} 頁 {} 英雄 進度{}/{}..." . 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()

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

代碼運行結果

Python通過requests模塊實現抓取王者榮耀全套皮膚

Python通過requests模塊實現抓取王者榮耀全套皮膚

到此這篇關于Python通過requests模塊實現抓取王者榮耀全套皮膚的文章就介紹到這了,更多相關Python 抓取王者榮耀皮膚內容請搜索服務器之家以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持服務器之家!

原文鏈接:https://blog.csdn.net/weixin_43649691/article/details/120992429

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 色8888www视频在线观看 | 久久久久久综合 | 欧美福利在线 | 人人射在线视频 | 夜夜骚av | 黄色国产在线视频 | 九色在线观看 | 一区二区三区精品 | 色天堂影院 | 精品久久久久久久久久久久 | 日韩成人一区二区 | 日韩中文字幕一区二区 | 精品一区二区在线观看 | 免费黄色在线观看 | 国产视频一区二区三区在线观看 | 操操碰| 大片免费播放在线观看视频 | 中文字幕在线观看 | 中文字幕av一区 | 亚洲一区 欧美 | 国产色秀视频在线观看 | 国产欧美精品一区二区三区 | 久久99精品一区二区三区 | 一区二区蜜桃 | 在线观看国产一区视频 | 中文字幕在线观看av | 欧美一区免费 | 国产精品久久久久久久久免费高清 | 亚洲高清免费视频 | 日韩一区二区精品 | 精品久久久精品 | 精品视频一区二区三区四区 | 欧美黄色片免费观看 | 丝袜久久| 玖玖玖视频 | 国产精品视频网 | 黄色美女网站视频 | 日韩成人精品 | 五月激情综合 | 免费一级毛片 | 在线国产视频观看 |