标签:art 源代码 port 提取 rest header window res sts
import requests import re api = ‘http://music.taihe.com/search?‘ header = { ‘User-Agent‘: ‘Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36‘ } data = { ‘key‘: ‘薛之谦‘ } response = requests.get(api, params=data, headers=header) response.encoding = ‘utf-8‘ html = response.text sids = re.findall(r‘data-playdata="(.+?)"‘, ‘html‘, re.S) print(sids) da1 = re.findall(r‘\d+‘, sids[0]) print(da1) for i in da1: url = r‘http://music.taihe.com/data/tingapi/v1/restserver/ting?method=baidu.ting.ugccenter.checkFollRedPoint×tamp={}?m=qTPtZ4RJPty%2BSRTk9J2nlD%2FpisYR9p8jVnkaoeV5DaI%3D&sign=bf2bac06f185709890e3d6abf56ad998&from=web‘.format(i) response = requests.get(url) data = response.text print(data) # 第一种提取方式 data1 = re.findall(r‘\((.*)\)‘, data)[0] print(data1) # JSON 格式转换 data2 = json.loads(data1) mp3_name =data2[‘songinfo‘][‘title‘] mp3_url = data2[‘baitrate‘][‘file_link‘] print(mp3_name) print(mp3_url) response = requests.get(mp3_url) with open(r‘./mp3/%s.mp3‘%mp3_name, ‘wb‘) as f: f.write(response.content)
标签:art 源代码 port 提取 rest header window res sts
原文地址:https://www.cnblogs.com/wordgao/p/9824685.html