没有封装,会封装的大佬,可以封装exe
[Python] 纯文本查看 复制代码def KuGou(singer, num):
key = urllib.parse.quote(singer)
url = f'https://songsearch.kugou.com/song_search_v2?keyword={key}&page={str(num)}'
try:
res = k_reqeust(url)
res_items = res.json().get('data')
page_size = res_items['pagesize']
total = res_items['total']
print(singer + f'相关歌曲共{total}首,共{page_size}页')
canshu()
num_key = input('请根据需求输入相关下载页面 a or b:')
page_num = input('请输入下载的页码:')
if int(page_num) > int(page_size):
print('页面超过下限,请重新开始')
exit()
if not page_num.isdigit():
print('让你输入数字,你输入啥玩意?')
exit()
if num_key == 'a':
a_url = f'https://songsearch.kugou.com/song_search_v2?keyword={key}&page={str(page_num)}'
res1 = k_reqeust(a_url)
items = res1.json().get('data')['lists']
k_dowaload(items)
elif num_key == 'b':
for page in range(1, int(page_num) + 1):
b_url = f'https://songsearch.kugou.com/song_search_v2?keyword={key}&page={page}'
res2 = k_reqeust(b_url)
items = res2.json().get('data')['lists']
k_dowaload(items)
else:
print('输入错误')
exit()
except Exception as e:
print(e)
exit()