liuyuqi-dellpc 2 years ago
parent
commit
24e951fc24
6 changed files with 144 additions and 0 deletions
  1. 2 0
      .gitignore
  2. 3 0
      .vscode/settings.json
  3. 25 0
      README.md
  4. 73 0
      getHero.py
  5. 40 0
      getHero.spec
  6. 1 0
      requirements.txt

+ 2 - 0
.gitignore

@@ -0,0 +1,2 @@
+/build/getHero
+/__pycache__

+ 3 - 0
.vscode/settings.json

@@ -0,0 +1,3 @@
+{
+    "python.pythonPath": ".venv\\Scripts\\python.exe"
+}

+ 25 - 0
README.md

@@ -0,0 +1,25 @@
+## crawl_hero
+
+英雄联盟游戏头像爬虫工具
+
+```
+# 2. 编写一个工具(LOL皮肤下载工具) ----封装的思想
+#   给用户展示所有的英雄名称和id (在控制台输出 所有英雄的名称和id  每三个为一行)
+#   用户输入想要的英雄皮肤   (用户输入所需要的英雄id)
+#   如果有,则进行下载,      判断id是否在英雄id列表中存在
+#   如果没有让用户从新输入    y 继续数据皮肤信息    n 输出程序结束
+
+
+```
+
+
+```
+
+virtualenv .venv 
+
+pip install -r requirements.txt
+
+pip install pyinstaller
+pyinstaller -F -c  getHero.py
+
+```

+ 73 - 0
getHero.py

@@ -0,0 +1,73 @@
+import requests
+import os
+
+'''
+@Contact :   liuyuqi.gov@msn.cn
+@Time    :   2022/03/08 21:12:55
+@License :   Copyright © 2017-2020 liuyuqi. All Rights Reserved.
+@Desc    :   
+
+# 2. 编写一个工具(LOL皮肤下载工具) ----封装的思想
+#   给用户展示所有的英雄名称和id (在控制台输出 所有英雄的名称和id  每三个为一行)
+#   用户输入想要的英雄皮肤   (用户输入所需要的英雄id)
+#   如果有,则进行下载,      判断id是否在英雄id列表中存在
+#   如果没有让用户从新输入    y 继续数据皮肤信息    n 输出程序结束
+'''
+
+
+hero_list_url = "https://game.gtimg.cn/images/lol/act/img/js/heroList/hero_list.js"
+s = requests.Session()
+hero_id_list = []
+
+
+def getHeroId():
+    global hero_id_list
+    response = s.get(hero_list_url).json()
+    hero_list = response["hero"]
+    print("-----------所有英雄id和名字--------------------")
+    input("按任意键继续")
+    index = 1
+    tmp = ""
+    for hero in hero_list:
+        tmp = tmp + hero["heroId"] + " " + hero["name"] + "    "
+        if index % 3 == 0:
+            print(tmp)
+            tmp = ""
+        hero_id_list.append(hero["heroId"])
+        index = index + 1
+
+
+def getHeroPic():
+    while(1):
+        mHeroId = input("用户输入所需要的英雄id:")
+      # 获取所有英雄图片的地址
+        for hero_id in hero_id_list:
+            if mHeroId == hero_id:
+                hero_img_url = "https://game.gtimg.cn/images/lol/act/img/js/hero/%s.js" % (
+                    hero_id)
+                skin_list = s.get(hero_img_url).json()["skins"]
+                for skin in skin_list:
+                    mainImg = skin["mainImg"]
+                    heroName = skin["heroName"]
+                    name = skin["name"]
+                    if not os.path.exists(heroName):
+                        os.mkdir(heroName)
+                    if mainImg == "":
+                        with open(heroName + "/" + name + ".jpg", "wb") as file:
+                            file.write(s.get(skin["chromaImg"]).content)
+                    else:
+                        with open(heroName + "/" + name + ".jpg", "wb") as file:
+                            file.write(s.get(skin["mainImg"]).content)
+        print("下载结束,头像保存至当前目录\r\n\r\n")
+        yn = input("y 继续    n 输出程序结束:")
+        if yn == "n":
+            exit()
+
+
+def getHero():
+    getHeroId()
+    getHeroPic()
+
+
+if __name__ == '__main__':
+    getHero()

+ 40 - 0
getHero.spec

@@ -0,0 +1,40 @@
+# -*- mode: python ; coding: utf-8 -*-
+
+
+block_cipher = None
+
+
+a = Analysis(['getHero.py'],
+             pathex=[],
+             binaries=[],
+             datas=[],
+             hiddenimports=[],
+             hookspath=[],
+             hooksconfig={},
+             runtime_hooks=[],
+             excludes=[],
+             win_no_prefer_redirects=False,
+             win_private_assemblies=False,
+             cipher=block_cipher,
+             noarchive=False)
+pyz = PYZ(a.pure, a.zipped_data,
+             cipher=block_cipher)
+
+exe = EXE(pyz,
+          a.scripts,
+          a.binaries,
+          a.zipfiles,
+          a.datas,  
+          [],
+          name='getHero',
+          debug=False,
+          bootloader_ignore_signals=False,
+          strip=False,
+          upx=True,
+          upx_exclude=[],
+          runtime_tmpdir=None,
+          console=True,
+          disable_windowed_traceback=False,
+          target_arch=None,
+          codesign_identity=None,
+          entitlements_file=None )

+ 1 - 0
requirements.txt

@@ -0,0 +1 @@
+requests