Python实训day06pm【网络爬虫(爬取接口)-爬取图片与数据】
- Python實訓-15天-博客匯總表
目錄
練習1
練習2
練習1
''' 課堂練習2:爬取lol英雄的頭像、BP的音樂。 需要找數據接口:https://101.qq.com/#/hero ''' import requests # from bs4 import BeautifulSoup as BS import 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('https://game.gtimg.cn/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('https://game.gtimg.cn/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
[('2021.12.27', 182), ('2021.12.31', 182), ('2022.01.10', 176), ('2021.12.30', 166), ('2021.12.26', 162), ('2021.12.25', 161), ('2021.12.29', 156), ('2021.12.28', 152), ('2022.01.09', 152), ('2022.01.01', 134), ('2022.01.05', 133), ('2021.12.16', 130), ('2022.01.06', 127), ('2021.12.12', 126), ('2021.12.11', 122), ('2021.12.17', 115), ('2022.01.03', 112), ('2021.12.02', 108), ('2022.01.02', 108), ('2021.12.14', 105), ('2021.12.15', 104), ('2022.01.08', 104), ('2021.12.22', 102), ('2022.01.07', 99), ('2021.12.03', 92), ('2021.12.06', 89), ('2021.12.24', 89), ('2021.12.08', 79), ('2021.12.13', 79), ('2021.12.07', 77), ('2021.12.05', 76), ('2021.12.01', 70), ('2021.12.21', 63), ('2021.12.23', 63), ('2021.12.20', 59), ('2021.12.10', 57), ('2022.01.04', 57), ('2021.12.09', 55), ('2021.12.18', 51), ('2021.12.04', 47), ('2021.12.19', 38)]
Process finished with exit code 0?
# 通過瀏覽器找到接口: url = 'https://api.inews.qq.com/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 >= '2021.12.01':tj[y + '.' + m] = l['localConfirmadd'];# print(tj)tj = list(tj.items()); # 轉為list tj.sort(key=lambda x: x[1], reverse=True); print(tj)瑣窗寒
誰點星燈,與月盈缺,分明影瘦。微云裁紗,凌波月吟將酒。溫又放。天寒煞也,試飲還卻紅爐守。非絲亦非帛,照與霜凝,冷落人秋。
枯木長腐朽。萬盡無他求,越歌已舊。衰草營營,死或生都苦口。垂雙目、收斂愁頭,簫聲起越人歌又。復誰有、橫吹平波,種種皆應后。
明月夜
我做輕紗,與夜黑白,分明閑歡。繁星點翠,婆娑清風伴舞。曼且樂。人極興也,欲醉且行貴相知。非冷亦非寒,明與眾生,逍遙人仙。
來去皆常事。但愿知己同,舞劍盼新。人生艾艾,樂與憂都淡漠。賞明月,游紗聽風。歡笑彼伏暇愈暇。同與我,吹笛撫琴,樣樣都有愁。
總結
以上是生活随笔為你收集整理的Python实训day06pm【网络爬虫(爬取接口)-爬取图片与数据】的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Python实训day06am【网络爬虫
- 下一篇: Python实训day07am【爬取数据