这是打开qq音乐 network网页请求URL的内容 我想要从响应中获取网页中歌曲名,但是我写完代码发现返回的值只有部分。
完整部分应该是这样的
这有啥解决办法吗?
完整部分应该是这样的
这有啥解决办法吗?
收起
当前问题酬金
¥ 0 (可追加 ¥500)
支付方式
扫码支付
data中包含中文,post数据的时候需要调用encode编码下数据,不能直接post,改下面就可以了。而且由于搜索需要登录才能用,所以要附加上登录后的cookie请求头,其他头可以不需要。而且注意数据节点位置
改下面就行了
import requests
headers = {'cookie':'pgv_pvi=8068807680; pgv_pvid=3148864639; RK=yUpAV2ICOK; ptcz=d942d8b68ecf2bbb5c631d8e483497f82a2383a6095115a2ef111d8b4b5961bb; pac_uid=1_155132206; iip=0; o_cookie=155132206; _ga=GA1.2.1287171002.1616477719; tvfe_boss_uuid=e03f06df4ca157b5; fqm_pvqid=e058d838-0783-4c5b-9192-d4cf8537465f; ts_uid=9533016972; fqm_sessionid=e14a85d6-fe2c-4a18-9fc6-7a34e7f3d5e5; pgv_info=ssid=s189196696; ts_last=y.qq.com/n/ryqq/search; _qpsvr_localtk=0.8821454753758016; login_type=1; wxopenid=; psrf_qqunionid=2DE541C9DAC816AB6FF21AE742464678; psrf_qqopenid=1481FDF15C80502E4B93ECDACF6517F7; psrf_qqrefresh_token=7081037E1B58739C39F70B6A50FB29D6; psrf_musickey_createtime=1647410156; wxrefresh_token=; wxunionid=; euin=oK4koKoAowns; tmeLoginType=2; psrf_qqaccess_token=0566E694A28A706BC7ABBA6FA3DC611C; uin=155132206; qm_keyst=Q_H_L_5t1rW3C28iWXqJC9X4YBNDgF__SlVLUddxnxCf1VGLN0bHYjNrag04w; psrf_access_token_expiresAt=1655186156; qm_keyst=Q_H_L_5t1rW3C28iWXqJC9X4YBNDgF__SlVLUddxnxCf1VGLN0bHYjNrag04w; qqmusic_key=Q_H_L_5t1rW3C28iWXqJC9X4YBNDgF__SlVLUddxnxCf1VGLN0bHYjNrag04w'
}
data ='{"comm":{"cv":4747474,"ct":24,"format":"json","inCharset":"utf-8","outCharset":"utf-8","notice":0,"platform":"yqq.json","needNewCode":1,"uin":155132206,"g_tk_new_20200303":1446837834,"g_tk":1446837834},"req_1":{"method":"DoSearchForQQMusicDesktop","module":"music.search.SearchCgiService","param":{"remoteplace":"txt.yqq.top","searchid":"57966588075123225","search_type":0,"query":"周杰伦","page_num":1,"num_per_page":10}}}'
url = 'https://u.y.qq.com/cgi-bin/musics.fcg?_=1647411323421&sign=zzbafd2829ekt6qco6tn9kb5dtdowz84g30315e4d'
res = requests.post(url,data=data.encode('utf-8'),headers=headers)
json_music = res.json()
#print(json_music)
list_music = json_music['req_1']['data']['body']['song']['list']
# list_music是一个列表,music是它里面的元素
for music in list_music:
# 以name为键,查找歌曲名
print(music['name'])
# 查找专辑名
print('所属专辑:'+music['album']['name'])
# 查找播放时长
print('播放时长:'+str(music['interval'])+'秒')
# 查找播放链接
print('播放链接:https://y.qq.com/n/yqq/song/'+music['mid']+'.html\n\n')
报告相同问题?