资源简介
python爬取王者荣耀官网信息,下载皮肤,头像,统计皮肤数量信息,笔记+源码

代码片段和文件信息
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2019/8/29 16:03
# @Author : Cxk
# @File : class6_511721010639_陈旋凯_down_img.py
“““
从csv读取数据
“““
import os
import requests
def read_csv():
file = open(“./herofile/hero.csv“ “r“ encoding=“gbk“)
# lines = file.read()
lines = file.readlines()
content = lines[1:]
# print(content)
lists = []
for hero_element in content:
# 空子典
hero_item = {}
# 切掉”\n“
hero = hero_element[:-1]
# print(hero)
hero_list = hero.split(““)
# print(hero_list)
hero_item[“hero_name“] = hero_list[0]
hero_item[“image_url“] = hero_list[1]
# print(hero_item)
lists.append(hero_item)
return lists
def save_img(hero_datas):
headers = {
“user-agent“: “Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML like Gecko) Chrome/76.0.3809.100 Safari/537.36“
}
# print(len(hero_datas)
dir_name = “./herofile/“
for image_element in hero_datas:
hero_name = image_element[“hero_name“]
image_url = image_element[“image_url“]
# print(image_url)
response = requests.get(image_url headers=headers)
image_content = response.content
# path=./herofile/鲁班/1 鲁班.jpg
paths = dir_name + hero_name + “/1 “ + hero_name + “.jpg“
# print(paths)
writer = open(paths “wb“)
writer.write(image_content)
writer.close()
print(“正在下载--(%s)--图片“ % hero_name)
print(“英雄头像下载完成!“)
def creat_hero_dirs(get_hero_info):
dir_before_name = “./herofile“
for hero_element in get_hero_info:
# print(hero_element)
# 获取元素元素
hero_name = hero_element[“hero_name“]
# print(hero_name)
hero_path = dir_before_name + “/“ + hero_name
# print(hero_path)
# 若目录不存在 创建
if not os.path.exists(hero_path):
os.makedirs(hero_path)
print(“目录创建成功!“)
def main():
get_hero_info = read_csv()
# 创建相应英雄名称目录
creat_hero_dirs(get_hero_info)
save_img(get_hero_info)
if __name__ == ‘__main__‘:
main()
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2019-09-01 17:37 源码\
文件 2372 2019-08-29 16:03 源码\down_img.py
文件 1749 2019-08-30 10:08 源码\down_skin.py
文件 2477 2019-08-29 16:09 源码\save_hero_csv.py
文件 3573 2019-08-29 17:00 源码\save_hero_json.py
文件 655707 2019-08-26 17:10 随堂笔记1.pdf
文件 1540427 2019-08-27 16:12 随堂笔记2.pdf
文件 951318 2019-08-28 15:24 随堂笔记3.pdf
文件 577446 2019-08-29 15:59 随堂笔记4.pdf
文件 517699 2019-08-30 15:47 随堂笔记5.pdf
相关资源
- 二级考试python试题12套(包括选择题和
- pywin32_python3.6_64位
- python+ selenium教程
- PycURL(Windows7/Win32)Python2.7安装包 P
- 英文原版-Scientific Computing with Python
- 7.图像风格迁移 基于深度学习 pyt
- 基于Python的学生管理系统
- A Byte of Python(简明Python教程)(第
- Python实例174946
- Python 人脸识别
- Python 人事管理系统
- 基于python-flask的个人博客系统
- 计算机视觉应用开发流程
- python 调用sftp断点续传文件
- python socket游戏
- 基于Python爬虫爬取天气预报信息
- python函数编程和讲解
- Python开发的个人博客
- 基于python的三层神经网络模型搭建
- python实现自动操作windows应用
- python人脸识别(opencv)
- python 绘图(方形、线条、圆形)
- python疫情卡UN管控
- python 连连看小游戏源码
- 基于PyQt5的视频播放器设计
- 一个简单的python爬虫
- csv文件行列转换python实现代码
- Python操作Mysql教程手册
- Python Machine Learning Case Studies
- python获取硬件信息
评论
共有 条评论