[Python] 纯文本查看 复制代码
import requests, json, sys, time, os
url_template = "http://service.picasso.adesk.com:80/v1/vertical/{}vertical?{}limit=16&skip={}&adult=false&first=1&url=http%3A%2F%2Fservice.picasso.adesk.com%2Fv1%2Fvertical%2F{}vertical&order={}"
order='new'
skip = [0 for x in range(17)]
med_url = []
category_dict = {
'1':["推荐", '','disorder=true&',skip[0],'','hot'],
'2':["最新", '','',skip[0],'',order],
'3':["美女", 'category/4e4d610cdf714d2966000000/','',skip[0],'category%2F4e4d610cdf714d2966000000%2F',order],
'4':["动漫", 'category/4e4d610cdf714d2966000003/','',skip[0],'category%2F4e4d610cdf714d2966000003%2F',order],
'5':["风景", 'category/4e4d610cdf714d2966000002/','',skip[0],'category%2F4e4d610cdf714d2966000002%2F',order],
'6':["游戏", 'category/4e4d610cdf714d2966000007/','',skip[0],'category%2F4e4d610cdf714d2966000007%2F',order],
'7':["文字", 'category/5109e04e48d5b9364ae9ac45/','',skip[0],'category%2F5109e04e48d5b9364ae9ac45%2F',order],
'8':["视觉", 'category/4fb479f75ba1c65561000027/','',skip[0],'category%2F4fb479f75ba1c65561000027%2F',order],
'9':["情感", 'category/4ef0a35c0569795756000000/','',skip[0],'category%2F4ef0a35c0569795756000000%2F',order],
'10':["设计", 'category/4fb47a195ba1c60ca5000222/','',skip[0],'category%2F4fb47a195ba1c60ca5000222%2F',order],
'11':["明星", 'category/5109e05248d5b9368bb559dc/','',skip[0],'category%2F5109e05248d5b9368bb559dc%2F',order],
'12':["物语", 'category/4fb47a465ba1c65561000028/','',skip[0],'category%2F4fb47a465ba1c65561000028%2F',order],
'13':["男人", 'category/4e4d610cdf714d2966000006/','',skip[0],'category%2F4e4d610cdf714d2966000006%2F',order],
'14':["机械", 'category/4e4d610cdf714d2966000005/','',skip[0],'category%2F4e4d610cdf714d2966000005%2F',order],
'15':["城市", 'category/4fb47a305ba1c60ca5000223/','',skip[0],'category%2F4fb47a305ba1c60ca5000223%2F',order],
'16':["动物", 'category/4e4d610cdf714d2966000001/','',skip[0],'category%2F4e4d610cdf714d2966000001%2F',order],
'17':["影视", 'category/4e58c2570569791a19000000/','',skip[0],'category%2F4e58c2570569791a19000000%2F',order]
}
def xh(url, file_name):
headers = {
'User-Agent': 'Mozilla/5.0 (X11; Linux armv7l) AppleWebKit/537.36 (KHTML, like Gecko) Raspbian Chromium/74.0.3729.157 Chrome/74.0.3729.157 Safari/537.36'
}
qq = requests.get(url, headers=headers).text
qq1 = json.loads(qq)
qq2 = qq1.get("res").get("vertical")
q = []
str_fmt = '{}图片-{}.jpg'
if not os.path.exists('C:\\Users\\zfx\\Desktop\\img'):
os.makedirs('C:\\Users\\zfx\\Desktop\\img\\')
for a in qq2:
q.append(a.get("img"))
for u in q:
print(u)
i = time.time()
fn = str_fmt.format(file_name, i)
try:
picture = requests.get(u).content
with open('C:\\Users\\zfx\\Desktop\\img\\' + fn, 'wb')as file:
file.write(picture)
except Exception as e:
print('错误:',e)
else:
print("下载成功~~",fn)
if __name__ == '__main__':
display= ''
for i in range(1,18):
display = display + '{}={},'.format(str(i), category_dict[str(i)][0])
display = display[:-1]
text = input(display+"\n请输入命令:")
index = 0
while True:
if text == 'q':
sys.exit('您已正常退出!')
if text == 'm':
text = input(display+"\n请输入命令:")
continue
elif text == '':
pass
elif text in list(category_dict.keys()):
index = text
else:
print("错误!!!")
item = category_dict[index]
url = url_template.format(item[1], item[2], item[3], item[4], item[5])
xh(url, item[0])
item[3] = item[3]+int(16)
category_dict[index] = item
text = input('“q”键退出,Enter继续执行,“m”键显示目录\n请输入命令:')