栄光のパイソンキング壁紙

効果は以下の通りです#

コードは以下のように表示されます#

#! /usr/bin/env python
# encoding: utf-8import os, time, requests, json, re
from retrying import retry
from urllib import parse

classHonorOfKings:

 def __init__(self, save_path='/Users/cuixiaoyan/Downloads'):
  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+'著者:cxy')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]else6print('---ダウンロード開始...')
  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 =0for 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):withopen(save_name,'wb')as f:
      response_content = self.request(hero_url.replace("/200","/0")).content
      f.write(response_content)
   offset +=1print('---ダウンロード完了...')

 @ 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()

Recommended Posts

栄光のパイソンキング壁紙
Pythonは、王の栄光のためにスキンのフルセットをクロールします
Python3.9の7つの機能
Python構文の基本
Pythonの基本構文
Pythonの基礎知識(1)
pythonのPrettytableモジュール
09.Python3の共通モジュール
Pythonはスキンのフルセットをクロールします
Pythonの基盤を統合する(4)
Python(7)の基盤を統合する
pythonリスト(LIST)の深い理解
Pythonのタプルの添え字
Python(6)の基盤を統合する
PythonクローラーのJSの分析
Python(5)の基盤を統合する
gomokuプログラムのPython実装
Pythonサンドボックスエスケープの分析
Python3.10のいくつかの新機能
Pythonマルチスレッドの深い理解
Pythonオブジェクト指向プログラミングの分析
OpenCVインストールのPythonバージョン
Pythonの9つの機能エンジニアリング手法
python描画モジュールのmatplotlib
パラメータを渡すPythonメソッド
Pythonの基盤を統合する(3)
Python共通モジュールのコレクション
pythonでのwheelの使用法
Pythonの対数法の要約
Python開発でのパンダの使用
Pythonプラグインメカニズムの詳細な実装
pythonシーケンスタイプの詳細な説明
pythonリストの逆トラバーサルの実装
IOU計算ケースのPython実装
魔法の方法とPythonの使用
Python変数スコープの詳細な理解
word2vec操作のPython予備実装
Pythonは中国語の4つの車輪を処理します
情報エントロピーの例のPython計算
pythonselenium操作cookieの実装
Python開発でのnumpyの使用
地主取引のPythonシミュレーション
Pythonの用途は何ですか
Pythonクローラーのスクレイピーシミュレーションログイン
Python条件付き制御ステートメントの分析
Python1のブラックハットプログラミングアプリケーション
Pythonでの辞書の詳細な使用法
pythonでのosパッケージの使用
Python関数のいくつかの一般的なモード
200のPython標準ライブラリの要約!
pythonクローラーのMongodbとpythonの相互作用
python3登録グローバルホットキーの実装
python学生管理システムの実装
pythonにはいくつかのバージョンがあります
python定義クラスの簡単な使用法
プライベート属性を呼び出すpythonのメソッドの概要
python操作redisのいくつかの例
Pythonモジュールの知識の完全な分析
pythonアクセスAlipayの操作例
Python文字列プーリングの前提
Python3.8の新機能の秘密