王者荣耀爬虫程序

"""
文档注释: 三引号 出现在文件开头
爬虫流程:1.请求 2.解析 3.保存
1. 需要找到请求地址(F12 调试工具 网络页签 刷新 搜索 查找)
url = "https://pvp.qq.com/web201605/js/herolist.json"
需要使用请求工具 urllib 包 (python 内置的请求工具)
2. 解析(遍历 提取目标数据)
3. 保存
"""

# 从urllib 包下导入 request请求工具
from urllib import request
# 导入 数据转换模块
import json

# 请求一个网址 将返回内容存入response响应对象
response = request.urlopen("https://pvp.qq.com/web201605/js/herolist.json")
# 读取结果 解码utf8 将最终内容放入response
response = response.read().decode("utf8")
# 将字符串response  转换为方便使用的对象
response = json.loads(response)
# 使用for遍历response
for data in response:
    # 解析中文名 和头像地址
    head_url = f'https://game.gtimg.cn/images/yxzj/img201606/heroimg/{data["ename"]}/{data["ename"]}.jpg'
    cname = data["cname"]
    # print(cname, head_url)
    # 向头像地址 再次发起请求
    head_response = request.urlopen(head_url)
    head_response = head_response.read()
    # 将返回的头像数据保存到文件
    file = open(f"./heads/{cname}.jpg", "wb")
    file.write(head_response)
    file.close()
    print(f"保存 {cname} 成功")

相关推荐

  1. 王者荣耀爬虫程序

    2024-07-12 18:42:04       22 阅读
  2. vscode 编写爬虫爬取王者荣耀壁纸

    2024-07-12 18:42:04       63 阅读
  3. 游戏分组/王者荣耀

    2024-07-12 18:42:04       42 阅读
  4. 王者荣耀铭文说明

    2024-07-12 18:42:04       27 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-12 18:42:04       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-12 18:42:04       72 阅读
  3. 在Django里面运行非项目文件

    2024-07-12 18:42:04       58 阅读
  4. Python语言-面向对象

    2024-07-12 18:42:04       69 阅读

热门阅读

  1. yarn的安装与配置 (秒懂yarn用法)

    2024-07-12 18:42:04       19 阅读
  2. 错误集1

    2024-07-12 18:42:04       20 阅读
  3. ES6 async 函数详解 (十)

    2024-07-12 18:42:04       21 阅读
  4. Linux下如何解压rar文件

    2024-07-12 18:42:04       24 阅读
  5. C# 建造者模式(Builder Pattern)

    2024-07-12 18:42:04       23 阅读
  6. Warning: could not connect to a running Ollama instance

    2024-07-12 18:42:04       18 阅读
  7. 大语言模型

    2024-07-12 18:42:04       20 阅读
  8. EasyExcel文档链接与使用示例

    2024-07-12 18:42:04       17 阅读