|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
先看我整理的
- # -*- coding: utf-8 -*-
- import urllib.request
- import json
- import os
- response = urllib.request.urlopen("https://pvp.qq.com/web201605/herolist.shtml")
- hero_json = json.loads(response.read())
- hero_num = len(hero_json)
- for i in range(hero_num):
- # 文件夹不存在则创建
- if not os.path.exists('C:\\Users\\Administrator\\Desktop\\heroskin\\'):
- os.mkdir('C:\\Users\\Administrator\\Desktop\\heroskin\\')
- save_dir = 'C:\\Users\\Administrator\\Desktop\\heroskin\\' + hero_json[i]['cname'] + '\\'
- if not os.path.exists(save_dir):
- os.mkdir(save_dir)
- # 获取英雄皮肤列表
- skin_names = hero_json[i]['skin_name'].split('|')
- for cnt in range(len(skin_names)):
- save_file_name = save_dir + hero_json[i]['cname'] + '-' +skin_names[cnt] + '.jpg'
- skin_url = 'https://pvp.qq.com/web201605/herolist.shtml'+str(hero_json[i]['ename'])+ '/' +str(hero_json[i]['ename'])+'-bigskin-' + str(cnt+1) +'.jpg'
- if not os.path.exists(save_file_name):
- urllib.request.urlretrieve(skin_url, save_file_name)
复制代码
这是报错的
- Traceback (most recent call last):
- File "C:\Users\Administrator\Desktop\新皮肤.py", line 13, in <module>
- hero_json = json.loads(response.read())
- File "D:\Python38\lib\json\__init__.py", line 343, in loads
- s = s.decode(detect_encoding(s), 'surrogatepass')
- UnicodeDecodeError: 'utf-8' codec can't decode byte 0xcd in position 278: invalid continuation byte
复制代码
我的目的是快速爬取王者荣耀所有英雄皮肤,支持持续更新,或者更新后修改网址,大佬可以详细教我么 |
|