import json
import requests
#========================================================
#两条横线之间粘贴复制的东西(cookies和header),否则会报错不能运行
#========================================================
photonum = 1234 #照片数量
infolist = []
conn = 0
def getinfo(lastMatchedMoment,realPhotoIndex):
global conn
print('----------------------------'+str(conn)+"-------------------------------")
conn+=1
data = {
'size': '100',
'state': 'active',
'smallPhotoScaleParams': 'image/resize,m_mfit,h_250,w_250',
'originalPhotoScaleParams': 'image/resize,m_mfit,h_1300,w_1300',
'cursor': str(lastMatchedMoment), 'photoIndex': str(realPhotoIndex)
}
response = requests.post('https://cloud.h2os.com/gallery/pc/listNormalPhotos', headers=headers, cookies=cookies,
data=data)
photos = json.loads(response.text).get('photos')
lastMatchedMoment = json.loads(response.text).get('lastMatchedMoment')
realPhotoIndex = json.loads(response.text).get('realPhotoIndex')
for key in photos.keys():
for a in photos.get(key):
id = a.get("id")
real = requests.post('https://cloud.h2os.com/gallery/pc/getRealPhotoUrls', headers=headers, cookies=cookies,data='ids=["'+id+'"]')
infolist.append([json.loads(real.text).get(id),a.get("title")])
if len(infolist)<photonum:
getinfo(lastMatchedMoment, realPhotoIndex)
else:
dowimg()
def dowimg():
con = 0
print(infolist)
for img in infolist:
dir = "img\\" + img[1] # 构造完整文件名称
print("图片名称"+dir)
f = requests.get(img[0])
with open(dir, "wb") as code:
code.write(f.content) # 保存文件
con+=1
print("下载进度",(con/photonum*100),"%")
getinfo(0,0)
print("图片地址获取完毕")