# -*- codeing = utf-8 -*- # [url=home.php?mod=space&uid=238618]@Time[/url] : 2021/2/20 16:12 # [url=home.php?mod=space&uid=686208]@AuThor[/url] : 老七疯狂吸氧 # [url=home.php?mod=space&uid=267492]@file[/url] kowyy.py # @Software:PyCharm import re import requests import os import time headers = { 'User-Agent': 'Chrome/10' } def main(): print('例如:罗大佑的网址是:[url]https://music.163.com/#/artist?id=3686'[/url],'\n','ID就是:3686') ID=input("请输入歌手ID:") url='https://music.163.com/artist?id='+ID html=requests.get(url,headers).text get_id(html) def get_id(html): findlink=re.compile(r'<a href="/song\?id=(\d*)">(.*?)</a></li><li>') findname=re.compile(r'<h2 id="artist-name" data-rid=\d* class="sname f-thide sname-max" title=".*?">(.*?)</h2>') singername=re.findall(findname,html)[0] creat(singername) ll=re.findall(findlink,html) for i in ll: savemusic(i[1],i[0]) time.sleep(0.5) def creat(singername): #创建文件夹 if not os.path.exists(singername): os.mkdir(singername) # 如果该目录不存在就创建它 os.chdir(singername) def savemusic(name,id): #保存文件 url='http://music.163.com/song/media/outer/url?id='+id+'.mp3' with open(name+'.m4a','wb') as f: print('歌曲《',name,'》 下载中***************') f.write(requests.get(url=url,headers=headers).content) f.close() print("《",name,"》下载完成") print('') if __name__ == '__main__': main()
python教程
python网易云音乐爬虫分享
精准像素
2021-09-04
共人阅读
上一篇:Python视频逐帧提取工具源码
相关推荐
- python爬虫
-
Python好看视频地址解析下载代码
#encoding:utf-8# 好看视频下载 import socketfrom urllib.request import urlopenimport urllibimport reimport timefrom pyquery import PyQuery as pqimport requestsfrom tqdm import tqdm # 打印进度条的库import gzip print('程序开始运...
-
python美女写真图库爬虫
import requestsfrom lxml import etreeimport csvfrom time import sleepimport osfrom concurrent.futures import ThreadPoolExecutor headers = { 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit...
-
笔趣阁小说网Python爬虫分享
#[url=https://www.biquge.info/wanjiexiaoshuo/]https://www.biquge.info/wanjiexiaoshuo/[/url] 笔趣阁小说全本爬虫import timeimport requestsimport osimport randomfrom lxml import etreeimport webbrowserheader = { "User-Agent": "Mo...