300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > Python实训day06pm【网络爬虫(爬取接口)-爬取图片与数据】

Python实训day06pm【网络爬虫(爬取接口)-爬取图片与数据】

时间:2022-02-11 23:15:50

相关推荐

Python实训day06pm【网络爬虫(爬取接口)-爬取图片与数据】

Python实训-15天-博客汇总表

目录

练习1

练习2

练习1

'''课堂练习2:爬取lol英雄的头像、BP的音乐。需要找数据接口:/#/hero'''import requests# from bs4 import BeautifulSoup as BSimport jsonhds = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.71 Safari/537.36'}resp = requests.get('/images/lol/act/img/js/heroList/hero_list.js?ts=2736472', headers=hds)ct = resp.content.decode('utf-8')# print(ct)info = json.loads(ct);hs = info['hero'];# print(hs)# 下载二进制(非文本)文件信息def binary_down(url, path):resp = requests.get(url, headers=hds)ct = resp.content;f = open(path, 'wb');f.write(ct);f.close();dr = r'C:\Users\lwx\Desktop\LOL\{}.{}'; # 本地目录for h in hs:name = h['name'];hid = h['heroId']; # 头像banAudio = h['banAudio']; # 音频1selectAudio = h['selectAudio']; # 音频2# 下载文件binary_down('/images/lol/act/img/skinloading/{}000.jpg'.format(hid), dr.format(name, 'jpg'));binary_down(banAudio, dr.format(name + "_ban", 'ogg'));binary_down(selectAudio, dr.format(name + "_select", 'ogg'));print("over:", name)

练习2

F:\Python38\python.exe F:/JetBrains/2pythonSpace/pythonCode/实训lwx作业/day06-pm-2.py

[('.12.27', 182), ('.12.31', 182), ('.01.10', 176), ('.12.30', 166), ('.12.26', 162), ('.12.25', 161), ('.12.29', 156), ('.12.28', 152), ('.01.09', 152), ('.01.01', 134), ('.01.05', 133), ('.12.16', 130), ('.01.06', 127), ('.12.12', 126), ('.12.11', 122), ('.12.17', 115), ('.01.03', 112), ('.12.02', 108), ('.01.02', 108), ('.12.14', 105), ('.12.15', 104), ('.01.08', 104), ('.12.22', 102), ('.01.07', 99), ('.12.03', 92), ('.12.06', 89), ('.12.24', 89), ('.12.08', 79), ('.12.13', 79), ('.12.07', 77), ('.12.05', 76), ('.12.01', 70), ('.12.21', 63), ('.12.23', 63), ('.12.20', 59), ('.12.10', 57), ('.01.04', 57), ('.12.09', 55), ('.12.18', 51), ('.12.04', 47), ('.12.19', 38)]

Process finished with exit code 0

# 通过浏览器找到接口:url = 'https://api./newsqa/v1/query/inner/publish/modules/list?modules=chinaDayAddList'import requests;import json;hds = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.71 Safari/537.36'}resp = requests.get(url, headers=hds);ct = resp.content.decode('utf-8');ct = json.loads(ct);ls = ct['data']['chinaDayAddList'];# print(ls)tj = {};for l in ls:y = l['y'];m = l['date']if y + '.' + m >= '.12.01':tj[y + '.' + m] = l['localConfirmadd'];# print(tj)tj = list(tj.items()); # 转为listtj.sort(key=lambda x: x[1], reverse=True);print(tj)

琐窗寒

谁点星灯,与月盈缺,分明影瘦。微云裁纱,凌波月吟将酒。温又放。天寒煞也,试饮还却红炉守。非丝亦非帛,照与霜凝,冷落人秋。

枯木长腐朽。万尽无他求,越歌已旧。衰草营营,死或生都苦口。垂双目、收敛愁头,箫声起越人歌又。复谁有、横吹平波,种种皆应后。

明月夜

我做轻纱,与夜黑白,分明闲欢。繁星点翠,婆娑清风伴舞。曼且乐。人极兴也,欲醉且行贵相知。非冷亦非寒,明与众生,逍遥人仙。

来去皆常事。但愿知己同,舞剑盼新。人生艾艾,乐与忧都淡漠。赏明月,游纱听风。欢笑彼伏暇愈暇。同与我,吹笛抚琴,样样都有愁。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。