4 Star 14 Fork 4

kzeng / Kai FM Player

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
get_info_153.py 2.83 KB
一键复制 编辑 原始数据 按行查看 历史
kzeng 提交于 2020-02-15 23:00 . come back
import requests
import json
import time
import random
headers = {
'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36',
'Accept-Language': 'en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7'
}
songs_list = []
song_item = {}
BCOOKIES = {
'_ga': 'GA1.2.1514915751.1580129035',
'_gid': 'GA1.2.1732654743.1580825117',
'ac': "1580825047",
'bid': 'pZkn_b3EOB8',
'flag': "ok"
}
# skus = ['103125239']
# ssrequest = requests.session()
# requests.utils.add_dict_to_cookiejar(ssrequest.cookies, BCOOKIES)
# url="http://www.xxx.com"
# ssrequest.get(url)
song_count = 1000
channel = 153 # work&study style
# channel = 3 # 70's style
# channel = 6 # yueyu
# channel = 2 # oumei
# huayu
# channel = 1
url = "https://douban.fm/j/v2/playlist?channel=153&kbps=128&client=s%3Amainsite%7Cy%3A3.0&app_name=radio_website&version=100&type=p&sid=1844568"
for i in range(song_count):
while True:
try:
payload = {
'channel': channel,
'kbps': 128,
'client': 's:mainsite|y:3.0',
'app_name': 'radio_website',
'version': 100,
'type': 's',
'sid': 1663021,
'pt': '',
'pb': 64,
'apikey': ''
# 'time': time.time()
}
time.sleep(1)
# r = requests.get('https://douban.fm/j/v2/playlist', params=payload, headers=headers, timeout=2)
ssrequest = requests.session()
requests.utils.add_dict_to_cookiejar(ssrequest.cookies, BCOOKIES)
# url="http://www.xxx.com"
# ssrequest.get(url)
r = ssrequest.get(url, headers=headers)
# r = requests.get(url, headers=headers)
print('--------------------')
d = r.json()
# print(d)
# print(d['song'][0])
print(d['song'][0]['title'])
song_item = {
'song_title': d['song'][0]['title'],
# 'avatar': d['song'][0]['avatar'],
'url': d['song'][0]['url'],
'song_img': d['song'][0]['picture'],
'public_time': d['song'][0]['public_time'],
'singers': d['song'][0]['singers'][0]['name']
}
songs_list.append(song_item)
print('get song info #:' + str(i))
# print(songs_list)
break
except:
print('try again ...')
# time.sleep(1)
# print(json.dumps(songs_list))
data = json.dumps(songs_list)
with open('songs_data_1000_channel_' + str(channel) + '.json', 'w') as outfile:
json.dump(data, outfile)
print('get {} songs, ok'.format(i+1))
JavaScript
1
https://gitee.com/kzeng/Kai-FM-Player.git
git@gitee.com:kzeng/Kai-FM-Player.git
kzeng
Kai-FM-Player
Kai FM Player
master

搜索帮助