自学爬虫第二篇,爬取bilibiliUP主相册
# -*- coding: UTF-8 -*-
from urllib import request
import json
import os
if __name__ == '__main__':
# 为up主单独创建文件夹
def createDir(path):
if not os.path.exists(path):
os.makedirs(path)
return
# 存储图片
def savePic(picSrc,savePath,picName):
savePath = savePath + picName
if not os.path.exists(savePath):
request.urlretrieve(picSrc, savePath, print('存储成功 %s' % savePath))
else:
print('当前文件已存在:%s' % picName)
return
# 爬取up主相册信息
def copyUpPhotos(upId,photoType):
url = 'https://api.vc.bilibili.com/link_draw/v1/doc/upload_count?uid=%s' % (mid)
photoCount,num = 0,0
res = request.urlopen(url)
resJson = json.load(res)
if resJson['code'] == 0 and resJson['data']['all_count']