##01##
import requests
from bs4 import BeautifulSoup
headers = {
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'zh-CN,zh;q=0.9',
'Connection': 'keep-alive',
'Cookie': '_ntes_nnid=5e3bfe2c5019b346a72c07dcca53137c,1539230035064; _ntes_nuid=5e3bfe2c5019b346a72c07dcca53137c; UM_distinctid=166614624fd4c0-0a3477445d6a3f-661f1574-1fa400-166614624fe10e; mp_MA-838B-E46B5704033F_hubble=%7B%22sessionReferrer%22%3A%20%22https%3A%2F%2Fyoudata.163.com%2Findex%2Fapply%3Fchannel%3DB_baidu_sjbb_X80%22%2C%22updatedTime%22%3A%201539230522820%2C%22sessionStartTime%22%3A%201539230274623%2C%22sendNumClass%22%3A%20%7B%22allNum%22%3A%2020%2C%22errSendNum%22%3A%200%7D%2C%22deviceUdid%22%3A%20%22718513ec-5979-4d1e-9d8f-1b8e14a795e8%22%2C%22persistedTime%22%3A%201539230274611%2C%22LASTEVENT%22%3A%20%7B%22eventId%22%3A%20%22c8bc572c94437e3178ddcbeb55c176bf1c25856b%22%2C%22time%22%3A%201539230522820%7D%2C%22currentReferrer%22%3A%20%22https%3A%2F%2Fyoudata.163.com%2Findex%2Fapply%3Fchannel%3DB_baidu_sjbb_X80%22%2C%22sessionUuid%22%3A%20%22198ad0b4-30fc-4900-89c4-4f19c24306c9%22%7D; mail_psc_fingerprint=6e77768441da082055ae54b708555c75; __oc_uuid=93ede0b0-0ddb-11e9-9fb5-a3cb88e1a5e1; Province=010; City=010; vjuids=-dc4b8aca0.1682bdf142d.0.af89e76d115d1; vjlast=1546924267.1547017727.13; NTES_YD_PASSPORT=tzwzHwo1Z0bZybWh6NVxqDpQ.CeSNtaWI8Gdjl_T8tHF7LHE7Muc9bw6e9x25faymnahDIdML1nigrphb5D_odh5P.tMvP.Ea4HZpKz8_JSdGtAZFYjpHvXaBhZyFKYlpilW3bTiZtPYnq0IpHZqW4oZ4i1xlTi4UDbbS18vJH12rdGJyaEMbph6hMApu0OJoTnfTTNUP.PIb; P_OINFO=ok8aqwcaamb7d6e061f09cb4885b4649cbfe23daee@wx.163.com|1547347764|0|open_wap|00&99|null#0|null|open_wap|ok8aqwcaamb7d6e061f09cb4885b4649cbfe23daee@wx.163.com; JSESSIONID-WYYY=u99ZnGVt9wnmG82DNqMkbg%5CKG5w%2B9czNlslw%2BSCJC46rqOt%2Fzm3%2B8fyOe13Z3vU4PJnUtriqp9HWppU1jJ3itp%2FU1rK9mDhHSidyQ%5CHlvTgEHbUxftq%5CfhZdz4xq%2BeEpBAVfack1%2B28K5Gry%2BlA%2BquI176Ju6FCmzKMzH%2FrA4roWuGVa%3A1547602931235; _iuqxldmzr_=32; __utma=94650624.835405209.1547601134.1547601134.1547601134.1; __utmc=94650624; __utmz=94650624.1547601134.1.1.utmcsr=baidu|utmccn=(organic)|utmcmd=organic; WM_NI=W8tmso3%2F5mJ7D41zCTFuKHl7kB%2FNNJUJc5mevsv6dEdjIdcUQotBQsQnghhfBBif9ZqEk5KAGoeb5BpUe9LNUs8O6KLfeYQsOsu38IijxwTgNVQl4eD4dxX979sk6mUXNUY%3D; WM_NIKE=9ca17ae2e6ffcda170e2e6eeabc149b48d8493fc7bbab08fb3c55e938f8e84b8648593ffb8e93ea68baa89b72af0fea7c3b92a95e8bc8ef265f1f1fb8ec93d88ecff9bc26086ab85a9ef3da99ee1afcd429796add6f06fb6adbad7e74fa8b68785e25f93b1bca3d47993b2a989eb6e829ea787bc52b39ba5d6ca4b85b1ab83b84ab48babdacf4697adf8b0b54190baabbad4798dadbbd4bb43abb6b898d76d8e8a9f8db76f88ecac99db33f5e7bd8cb567978882b6dc37e2a3; WM_TID=fdH66tvKguVAFUFUVUNogWZ1TnvLVewo; __utmb=94650624.10.10.1547601134',
'Host': 'music.163.com',
'Referer': 'https://music.163.com/',
'Upgrade-Insecure-Requests': '1',
'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.92 Safari/537.36'
}
def save_artist(group_id, initial, hot_artist_dic, artisti_dic):
params = {'id': group_id, 'initial': initial}
r = requests.get('http://music.163.com/discover/artist/cat',headers=headers, params=params)
# 网页解析
soup = BeautifulSoup(r.content.decode(), 'html.parser')
body = soup.body
hot_artists = body.find_all('a', attrs={'class': 'msk'})
artists = body.find_all('a', attrs={'class': 'nm nm-icn f-thide s-fc0'})
for artist in hot_artists:
artist_id = artist['href'].replace('/artist?id=', '').strip()
artist_name = artist['title'].replace('的音乐', '')
try:
hot_artist_dic[artist_id] = artist_name
except Exception as e:
# 打印错误日志
print(e)
for artist in artists:
artist_id = artist['href'].replace('/artist?id=', '').strip()
artist_name = artist['title'].replace('的音乐', '')
try:
artist_dic[artist_id] = artist_name
except Exception as e:
# 打印错误日志
print(e)
#return artist_dic, hot_artist_dic
gg=1001
initial = 0
artist_dic = {}
hot_artist_dic = {}
save_artist(gg, initial, hot_artist_dic, artist_dic )
artist_dic
{'1140028': '承利', '1142011': '王极', '1142042': '徐梦圆', '1151001': '未来星B3Rich', '1158100': '留声玩具', '1159045': '齐一', '1185054': '尚先生', '1194094': '孤矢', '1197168': '徐秉龙', '1198010': '暗杠', '1198071': 'HOPE-T', '12002184': 'AR(刘夫阳)', '12002248': '沈以诚', '12027624': '栗先达', '1203045': '艾热', '1204010': 'Tizzy T', '12050022': '裂天', '12050049': 'AirJordy', '12052056': 'Fi9江澈', '12059094': 'JAEFOREAL', '12079066': 'Lil.Jet', '12079186': 'Al\xa0Rocco', '12079219': '李佳隆', '12083175': '排骨教主', '12083570': 'YKEY', '12084229': '焦迈奇', '12085016': '接个吻,开一枪', '12085017': 'BLOWFEVER', '12085569': '李蚊香', '1209003': 'LuckyMaxx', '12094099': '徐真真', '12094419': '羽肿', '12094558': 'Buzzy', '12114094': '马英伦', '12118230': '钱正昊', '12119569': '李迦南Doc', '12126098': 'Vk', '12127154': '吴海啸', '12127564': '艾福杰尼', '12138252': '张雪飞', '12138269': '毛不易', '12146142': '大壮', '12158033': '张佳伦', '12174057': '艾辰', '12174110': '崔开潮', '12185042': '特曼', '12194650': 'KT', '12199576': '小青龙', '12205140': '青柠', '12205361': '刘莱斯', '12236125': '王以太', '12259217': 'allenvee', '12268138': 'Todd\xa0Li', '12270575': '孟凡明', '12271965': 'Sand', '12276430': 'Cubi', '12282733': '黑崎子', '12286700': '虎二', '12287118': 'Ayo97', '12287780': '前男友', '12319383': '胖胖胖', '12350853': 'Red\xa0Monkey', '12360230': 'Lil-7', '12367021': 'AlimjanHasan', '12420149': '李袁杰', '12429072': '隔壁老樊', '12453329': '功夫胖KungFuPen', '12464053': 'PRC\xa0巴音汗', '12476238': '英镑', '12489984': '掌嘴', '12520754': 'DJ-荣大大', '12570017': 'MOMINJAN_ABLIKIM穆明江', '12606272': '吕大叶', '12641765': '江辰', '12760978': '广东雨神', '12782871': '$唐老师', '12798217': '刘思鉴', '12798308': '马子林Broma', '12852558': 'Y\xa0U\xa0Jay', '12905881': 'DJ\xa0Mr.Zi', '12932368': '蔡徐坤', '12969396': 'MOONBOI(杨望舒)', '13112541': 'Gibb-Z', '13145283': 'ICE', '13152025': '杨多', '13286745': 'еяхат\xa0музыка', '13296197': '二狗村高富帅', '13445026': '小君', '13527275': 'Wya乌鸦', '13609637': '马良', '13906123': '张紫豪', '14857181': '情词尧', '15064461': '方宇杰', '27862910': '者思范Remix', '28304970': '万能青年', '28868804': '寅子', '29069586': '王小帅', '30647258': 'DJ杨硕', '790044': '小峰峰', '977173': '3Bangz'}
for i in range(65, 91):
save_artist(gg, i, hot_artist_dic, artist_dic )
## 别运行它 ##
## 会重新覆盖掉 ##
import json
with open('save_artist_dict.json','w') as f:
json.dump(artist_dic,f)
with open('save_hot_artist_dict.json','w') as f:
json.dump(hot_artist_dic,f)
# ##01##
# import json
# dd= json.load(open('save_artist_dict.json'))
# # dd
##01##
artist_dic ={}
artist_dic = dd
headers = {
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Accept-Encoding': 'gzip, deflate, sdch',
'Accept-Language': 'zh-CN,zh;q=0.8,en;q=0.6',
'Cache-Control': 'no-cache',
'Connection': 'keep-alive',
'Cookie': '_ntes_nnid=7eced19b27ffae35dad3f8f2bf5885cd,1476521011210; _ntes_nuid=7eced19b27ffae35dad3f8f2bf5885cd; usertrack=c+5+hlgB7TgnsAmACnXtAg==; Province=025; City=025; _ga=GA1.2.1405085820.1476521280; NTES_PASSPORT=6n9ihXhbWKPi8yAqG.i2kETSCRa.ug06Txh8EMrrRsliVQXFV_orx5HffqhQjuGHkNQrLOIRLLotGohL9s10wcYSPiQfI2wiPacKlJ3nYAXgM; P_INFO=hourui93@163.com|1476523293|1|study|11&12|jis&1476511733&mail163#jis&320100#10#0#0|151889&0|g37_client_check&mailsettings&mail163&study&blog|hourui93@163.com; JSESSIONID-WYYY=189f31767098c3bd9d03d9b968c065daf43cbd4c1596732e4dcb471beafe2bf0605b85e969f92600064a977e0b64a24f0af7894ca898b696bd58ad5f39c8fce821ec2f81f826ea967215de4d10469e9bd672e75d25f116a9d309d360582a79620b250625859bc039161c78ab125a1e9bf5d291f6d4e4da30574ccd6bbab70b710e3f358f%3A1476594130342; _iuqxldmzr_=25; __utma=94650624.1038096298.1476521011.1476588849.1476592408.6; __utmb=94650624.11.10.1476592408; __utmc=94650624; __utmz=94650624.1476521011.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)',
'DNT': '1',
'Host': 'music.163.com',
'Pragma': 'no-cache',
'Referer': 'http://music.163.com/',
'Upgrade-Insecure-Requests': '1',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36'
}
def save_albums(artist_id, albume_dic):
params = {'id': artist_id, 'limit': '200'}
# 获取歌手个人主页
r = requests.get('http://music.163.com/artist/album', headers=headers, params=params)
# 网页解析
soup = BeautifulSoup(r.content.decode(), 'html.parser')
body = soup.body
albums = body.find_all('a', attrs={'class': 'tit s-fc0'}) # 获取所有专辑
for album in albums:
albume_id = album['href'].replace('/album?id=', '')
albume_dic[albume_id] = artist_id
albume_dic = {}
#for i in artist_dic.keys()
save_albums(2747, albume_dic)
albume_dic
{'2478699': 2747, '3233534': 2747, '3233776': 2747, '3261022': 2747, '3266290': 2747, '3266292': 2747, '3266298': 2747, '3266912': 2747, '3266915': 2747, '3266920': 2747, '3287239': 2747, '34428052': 2747, '34430036': 2747, '34798078': 2747, '35104158': 2747, '35623240': 2747, '35889034': 2747, '38512406': 2747, '8160': 2747, '8163': 2747, '8166': 2747, '8169': 2747, '8177': 2747, '8182': 2747, '8184': 2747, '8198': 2747, '8205': 2747, '8209': 2747, '8218': 2747, '8221': 2747, '8227': 2747, '8238': 2747, '8242': 2747, '8244': 2747, '8247': 2747, '8256': 2747, '8265': 2747, '8275': 2747, '8282': 2747, '8290': 2747, '8299': 2747, '8306': 2747, '8309': 2747, '8315': 2747, '8318': 2747, '8320': 2747, '8321': 2747, '8324': 2747, '8328': 2747, '8331': 2747, '8334': 2747, '8336': 2747, '8339': 2747, '8341': 2747, '8344': 2747, '8347': 2747, '8349': 2747, '8350': 2747, '8353': 2747, '8355': 2747, '8356': 2747, '8362': 2747, '8365': 2747, '8367': 2747, '8369': 2747, '8372': 2747, '8373': 2747, '8375': 2747, '8378': 2747, '8381': 2747, '8387': 2747, '8390': 2747, '8394': 2747}
##不要运行它 会覆盖掉 ##
import json
with open('save_albume_dict.json','w') as f:
json.dump(albume_dic,f)
# ##01##
# import json
# kk = json.load(open('save_albume_dict.json'))
# kk
kk['36074293']
'12085017'
len(albume_dic)
29977
albume_dic = {}
albume_dic = kk
headers = {
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Accept-Encoding': 'gzip, deflate, sdch',
'Accept-Language': 'zh-CN,zh;q=0.8,en;q=0.6',
'Cache-Control': 'no-cache',
'Connection': 'keep-alive',
'Cookie': '_ntes_nnid=7eced19b27ffae35dad3f8f2bf5885cd,1476521011210; _ntes_nuid=7eced19b27ffae35dad3f8f2bf5885cd; usertrack=c+5+hlgB7TgnsAmACnXtAg==; Province=025; City=025; NTES_PASSPORT=6n9ihXhbWKPi8yAqG.i2kETSCRa.ug06Txh8EMrrRsliVQXFV_orx5HffqhQjuGHkNQrLOIRLLotGohL9s10wcYSPiQfI2wiPacKlJ3nYAXgM; P_INFO=hourui93@163.com|1476523293|1|study|11&12|jis&1476511733&mail163#jis&320100#10#0#0|151889&0|g37_client_check&mailsettings&mail163&study&blog|hourui93@163.com; _ga=GA1.2.1405085820.1476521280; JSESSIONID-WYYY=fb5288e1c5f667324f1636d020704cab2f27ee915622b114f89027cbf60c38be2af6b9cbef2223c1f2581e3502f11b86efd60891d6f61b6f783c0d55114f8269fa801df7352f5cc4c8259876e563a6bd0212b504a8997723a0593b21d5b3d9076d4fa38c098be68e3c5d36d342e4a8e40c1f73378cec0b5851bd8a628886edbdd23a7093%3A1476623819662; _iuqxldmzr_=25; __utma=94650624.1038096298.1476521011.1476610320.1476622020.10; __utmb=94650624.14.10.1476622020; __utmc=94650624; __utmz=94650624.1476521011.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)',
'DNT': '1',
'Host': 'music.163.com',
'Pragma': 'no-cache',
'Referer': 'http://music.163.com/',
'Upgrade-Insecure-Requests': '1',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36'
}
def save_music(album_id, music_dic):
params = {'id': album_id}
# 获取专辑对应的页面
r = requests.get('http://music.163.com/album', headers=headers, params=params)
# 网页解析
soup = BeautifulSoup(r.content.decode(), 'html.parser')
body = soup.body
musics = body.find('ul', attrs={'class': 'f-hide'}).find_all('li') # 获取专辑的所有音乐
for music in musics:
music = music.find('a')
music_id = music['href'].replace('/song?id=', '')
music_name = music.getText()
music_dic[music_id] = [music_name, album_id]
# flush print
import sys
def flushprint(d):
sys.stdout.write('\r')
sys.stdout.write(str(d))
sys.stdout.flush()
music_dic={}
save_music(8160,music_dic)
music_dic
{'463268802': ['传奇三部曲', 8160], '82795': ['唱一遍一遍', 8160], '82799': ['传奇', 8160], '82803': ['偏爱水中月', 8160], '82807': ['倾国倾城', 8160], '82811': ['忘不了', 8160], '82814': ['苏三采茶', 8160], '82817': ['三部情曲', 8160], '82820': ['舍不得把眼睛睁开', 8160], '82824': ['玫瑰寄情', 8160], '82828': ['幸福在这里', 8160]}
import random
import time
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import requests, threading, datetime
from lxml import etree
import random
"""
1、抓取西刺代理网站的代理ip
2、并根据指定的目标url,对抓取到ip的有效性进行验证
3、最后存到指定的path
"""
# ------------------------------------------------------文档处理--------------------------------------------------------
# 写入文档
def write(path,text):
with open(path, 'a', encoding='utf-8') as f:
f.writelines(text)
f.write('\n')
# 清空文档
def truncatefile(path):
with open(path, 'w', encoding='utf-8') as f:
f.truncate()
# 读取文档
def read(path):
with open(path, 'r', encoding='utf-8') as f:
txt = []
for s in f.readlines():
txt.append(s.strip())
return txt
# ----------------------------------------------------------------------------------------------------------------------
# 计算时间差,格式: 时分秒
def gettimediff(start,end):
seconds = (end - start).seconds
m, s = divmod(seconds, 60)
h, m = divmod(m, 60)
diff = ("%02d:%02d:%02d" % (h, m, s))
return diff
# ----------------------------------------------------------------------------------------------------------------------
'''返回一个随机的请求头 headers'''
def getheaders():
user_agent_list = [
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/22.0.1207.1 Safari/537.1",
"Mozilla/5.0 (X11; CrOS i686 2268.111.0) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11",
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.6 (KHTML, like Gecko) Chrome/20.0.1092.0 Safari/536.6",
"Mozilla/5.0 (Windows NT 6.2) AppleWebKit/536.6 (KHTML, like Gecko) Chrome/20.0.1090.0 Safari/536.6",
"Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/19.77.34.5 Safari/537.1",
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.9 Safari/536.5",
"Mozilla/5.0 (Windows NT 6.0) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.36 Safari/536.5",
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.3 (KHTML, like Gecko) Chrome/19.0.1063.0 Safari/536.3",
"Mozilla/5.0 (Windows NT 5.1) AppleWebKit/536.3 (KHTML, like Gecko) Chrome/19.0.1063.0 Safari/536.3",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_0) AppleWebKit/536.3 (KHTML, like Gecko) Chrome/19.0.1063.0 Safari/536.3",
"Mozilla/5.0 (Windows NT 6.2) AppleWebKit/536.3 (KHTML, like Gecko) Chrome/19.0.1062.0 Safari/536.3",
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.3 (KHTML, like Gecko) Chrome/19.0.1062.0 Safari/536.3",
"Mozilla/5.0 (Windows NT 6.2) AppleWebKit/536.3 (KHTML, like Gecko) Chrome/19.0.1061.1 Safari/536.3",
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.3 (KHTML, like Gecko) Chrome/19.0.1061.1 Safari/536.3",
"Mozilla/5.0 (Windows NT 6.1) AppleWebKit/536.3 (KHTML, like Gecko) Chrome/19.0.1061.1 Safari/536.3",
"Mozilla/5.0 (Windows NT 6.2) AppleWebKit/536.3 (KHTML, like Gecko) Chrome/19.0.1061.0 Safari/536.3",
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.24 (KHTML, like Gecko) Chrome/19.0.1055.1 Safari/535.24",
"Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/535.24 (KHTML, like Gecko) Chrome/19.0.1055.1 Safari/535.24"
]
UserAgent = random.choice(user_agent_list)
headers = {'User-Agent': UserAgent}
return headers
'''检查ip是否可用'''
def checkip(targeturl,ip):
headers = getheaders() # 定制请求头
proxies = {"http": "http://"+ip, "https": "http://"+ip} # 代理ip
try:
response = requests.get(url=targeturl, proxies=proxies, headers=headers, timeout=5).status_code
if response == 200:
return True
else:
return False
except:
return False
'''获取代理方法'''
# 免费代理 XiciDaili
def findip(type,pagenum,targeturl,path): # ip类型,页码,目标url,存放ip的路径
list = {
'1': 'http://www.xicidaili.com/nt/', # xicidaili国内普通代理
'2': 'http://www.xicidaili.com/nn/', # xicidaili国内高匿代理
'3': 'http://www.xicidaili.com/wn/', # xicidaili国内https代理
'4': 'http://www.xicidaili.com/wt/' # xicidaili国外http代理
}
url = list[str(type)]+str(pagenum) # 配置url
headers = getheaders() # 定制请求头
html = requests.get(url=url, headers=headers, timeout=5).text
doc = etree.HTML(html)
all = doc.xpath('.//table[@id="ip_list"]/tr')
for i in all:
t = i.xpath('td/text()')
if len(t) > 0:
ip = t[0] + ':' + t[1]
if t[5]:
is_avail = checkip(targeturl, ip)
if is_avail == True:
ip = t[5].strip() + ':' + ip
write(path=path, text=ip)
print(ip)
'''多线程抓取ip入口'''
def getip(targeturl,path):
truncatefile(path) # 爬取前清空文档
start = datetime.datetime.now() # 开始时间
threads = []
for type in range(4): # 四种类型ip,每种类型取前三页,共12条线程
for pagenum in range(3):
t = threading.Thread(target=findip, args=(type+1, pagenum+1, targeturl, path))
threads.append(t)
print('开始爬取代理ip')
for s in threads: # 开启多线程爬取
s.start()
for e in threads: # 等待所有线程结束
e.join()
print('爬取完成')
# end = datetime.datetime.now() # 结束时间
# diff = gettimediff(start, end) # 计算耗时
ips = read(path) # 读取爬到的ip数量
print('一共爬取代理ip: %s 个 \n' % (len(ips)))
# print('一共爬取代理ip: %s 个,共耗时: %s \n' % (len(ips), diff))
'''启动'''
if __name__ == '__main__':
path = 'ip.txt' # 存放爬取ip的文档path
targeturl = 'http://www.cnblogs.com/TurboWay/' # 验证ip有效性的指定url
getip(targeturl, path)
开始爬取代理ip HTTPS:218.22.7.62:53281 HTTPS:218.22.7.62:53281 HTTP:113.116.144.227:9000 HTTP:113.116.145.206:9000 HTTP:27.37.47.244:9000 HTTPS:27.14.146.188:8118 HTTP:116.209.57.11:9999 HTTPS:119.176.66.90:9999 HTTPS:116.209.53.204:9999 HTTP:111.75.193.24:48449 HTTPS:61.189.242.243:55484 HTTPS:210.5.10.87:53281 HTTP:121.8.107.13:8080 HTTPS:27.191.234.69:9999 HTTPS:121.69.13.242:53281 HTTPS:58.240.220.86:53281 HTTPS:203.86.3.22:8080 HTTPS:61.128.208.94:3128 HTTPS:218.241.219.226:9999 HTTP:222.74.61.98:53281 HTTPS:121.69.13.242:53281 HTTP:113.116.146.188:9000 HTTP:211.162.70.229:3128 HTTPS:113.65.5.181:8118 HTTPS:27.191.234.69:9999 HTTPS:14.118.130.213:8081 HTTP:60.190.153.150:8080 HTTP:113.116.146.8:9000 HTTP:101.251.216.103:8080 HTTPS:113.65.5.181:8118 HTTPS:110.52.235.214:9999 HTTPS:121.69.46.178:9000 HTTPS:115.231.5.230:44524 HTTP:116.209.59.81:9999 HTTPS:59.45.16.10:59156 HTTPS:122.141.74.186:8080 HTTP:182.111.129.37:53281 HTTPS:115.231.5.230:44524 HTTPS:59.45.16.10:59156 HTTPS:60.184.194.157:3128 HTTP:115.171.203.189:9000 HTTP:125.46.0.62:53281 HTTPS:203.86.3.22:8080 HTTPS:218.241.219.226:9999 HTTP:221.227.39.160:8118 HTTPS:124.152.32.140:53281 HTTP:113.116.146.188:9000 HTTP:211.162.70.229:3128 HTTP:221.210.120.153:54402 HTTPS:110.250.65.108:8118 HTTPS:115.171.203.73:9000 HTTPS:221.205.111.210:9797 HTTP:182.111.129.37:53281 HTTP:112.95.190.10:9797 HTTP:125.46.0.62:53281 HTTPS:121.69.46.178:9000 HTTP:59.44.247.194:9797 HTTPS:180.141.90.172:53281 HTTP:113.200.214.164:9999 HTTPS:58.240.220.86:53281 HTTP:61.176.223.7:58822 HTTP:221.210.120.153:54402 HTTP:218.75.10.58:8080 HTTP:222.74.61.98:53281 HTTPS:116.209.53.204:9999 HTTP:218.28.58.150:53281 HTTP:111.177.183.32:9999 HTTPS:116.209.55.150:9999 HTTPS:183.30.204.154:9999 HTTPS:124.152.32.140:53281 HTTPS:113.54.152.170:8080 HTTPS:113.140.1.82:53281 HTTP:14.118.130.214:8081 HTTPS:111.198.154.116:8888 HTTP:221.205.111.7:9797 HTTPS:117.90.0.10:8118 HTTP:123.133.41.104:53281 HTTP:221.7.255.168:8080 HTTPS:110.250.65.108:8118 HTTP:113.200.214.164:9999 HTTPS:140.210.4.143:53281 HTTPS:61.128.208.94:3128 HTTP:101.231.50.154:8000 :118.24.148.74:8080 HTTP:218.28.58.150:53281 HTTPS:121.40.78.138:3128 HTTPS:36.110.14.186:3128 HTTP:110.52.235.155:9999 HTTP:116.196.90.181:3128 HTTPS:27.17.45.90:43411 HTTPS:110.52.235.41:9999 HTTPS:114.119.116.92:61066 HTTP:221.227.39.160:8118 HTTPS:117.114.149.66:53281 HTTPS:112.74.207.50:3128 HTTPS:101.132.122.230:3128 HTTPS:116.62.149.245:8118 HTTP:116.196.90.181:3128 HTTP:116.209.55.243:9999 HTTP:116.209.56.244:9999 HTTPS:123.117.36.233:9000 爬取完成 一共爬取代理ip: 101 个
# music_dic = {}
# for k, i in enumerate(kk.keys()):
# #time.sleep(+random.random())
# flushprint(k)
# if k % 100 == 0:
# print('this is the music of :' + str(k))
# try:
# save_music(i, music_dic)
# except Exception as e:
# print(i)
# print(e)
# if k % 2000 == 0:
# with open('save_music_dict{}.json'.format(k//2000),'w') as f:
# json.dump(music_dic,f)
# print('保存到了:',k)
# misic_dic.clear()
# music_dic = {}
music_dic = {}
k = 10001
i = 10001
# music_dic = {}
# for k, i in enumerate(kk.keys()):
# #time.sleep(1.0+random.random())
# flushprint(k)
# if k % 1000 == 0:
# print('this is the music of :' + str(k))
# try:
# save_music(i, music_dic)
# except Exception as e:
# print(i)
# print(e)
# if k % 5000 == 0:
# with open('save_music_dict01{}.json'.format(k//5000),'w') as f:
# json.dump(music_dic,f)
# print('保存到了:',k)
# #misic_dic.clear()
# music_dic = {}
# for k, i in enumerate(kk.keys()):
# #time.sleep(1.0+random.random())
# flushprint(k)
# if k % 1000 == 0 and k != 0:
# print('this is the music of :' + str(k))
# time.sleep(60.0)
# try:
# save_music(i, music_dic)
# except Exception as e:
# print('#'+i)
# print(e)
# if k % 5000 == 0 and k != 0:
# with open('save_music_dict03{}.json'.format(k//5000),'w') as f:
# json.dump(music_dic,f)
# print('保存到了:',k)
# #misic_dic.clear()
import json
with open('save_music_dict01.json','w') as f:
json.dump(music_dic,f)
# import json
# jj = json.load(open('save_music_dict01.json'))
# jj
len(jj)
111898
import json
with open('save_music_dict.json','w') as f:
json.dump(music_dic,f)
# import json
# jj = json.load(open('save_music_dict.json'))
# jj
len(jj)
110918
music_dic = {}
music_dic = jj
# import requests
# import re
# import csv
# import json
# class SingerSpider(object):
# def __init__(self):
# self.headers = {
# 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
# 'Accept-Encoding': 'gzip, deflate',
# 'Accept-Language': 'zh-CN,zh;q=0.9',
# 'Connection': 'keep-alive',
# 'Host': 'music.163.com',
# 'Referer': 'http://music.163.com/',
# 'Upgrade-Insecure-Requests': '1',
# 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) '
# 'Chrome/66.0.3359.181 Safari/537.36'
# }
# def get_index(self, url):
# '请求模块'
# try:
# resp = requests.get(url,headers=self.headers)
# if resp.status_code == 200:
# self.parse_re(resp.text)
# else:
# print('error')
# except ConnectionError:
# self.get_index(url)
# def parse_re(self, resp):
# '解析模块'
# print('start parse {}'.format(url))
# tags = re.findall(r'<a href=".*?/artist\?id=(\d+)" class="nm nm-icn f-thide s-fc0" title=".*?的音乐">(.*?)</a>', resp, re.S)
# title = re.findall(r'<title>(.*?)-.*?</title>', resp, re.S)
# for tag in tags:
# # print(tag[0],tag[1])
# self.save_json(tag, title)
# #self.save_csv(tag, title)
# def save_csv(self, tag, title):
# '存储模块'
# print('start save {}'.format(url))
# with open('all_singer.csv', 'a+', newline='', encoding='utf-8') as f:
# writer = csv.writer(f)
# writer.writerow((tag[0], tag[1], title[0]))
# print('finish spider {}'.format(url))
# def save_json(self, tag, title):
# print('start save {}'.format(url))
# s = json.dumps({'id': tag[0], 'name': tag[1], 'title': title[0]},ensure_ascii=False)
# with open('all_singer.json', 'a+', newline='', encoding='utf-8') as f:
# f.write(s)
# print('finish spider {}'.format(url))
# print(s)
# if __name__ == '__main__':
# # 歌手分类id
# list1 = [1001, 1002, 1003, 2001, 2002, 2003, 6001, 6002, 6003, 7001, 7002, 7003, 4001, 4002, 4003]
# # initial的值
# list2 = [0,65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90]
# for i in list1:
# for j in list2:
# url = 'http://music.163.com/discover/artist/cat?id=' + str(i) + '&initial=' + str(j)
# print('start spider {}'.format(url))
# SingerSpider().get_index(url)
# #原文:https://blog.csdn.net/wanhaiwei/article/details/84327561
# f = open(r'C://Users/Administrator/all_singer.csv','r',encoding='utf-8')
# g=f.read()
# print(g)
# f.close()
headers = {
'Host': 'music.163.com',
'Connection': 'keep-alive',
'Content-Length': '484',
'Cache-Control': 'max-age=0',
'Origin': 'http://music.163.com',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.84 Safari/537.36',
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': '*/*',
'DNT': '1',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,zh;q=0.8,en;q=0.6,zh-TW;q=0.4',
'Cookie': 'JSESSIONID-WYYY=b66d89ed74ae9e94ead89b16e475556e763dd34f95e6ca357d06830a210abc7b685e82318b9d1d5b52ac4f4b9a55024c7a34024fddaee852404ed410933db994dcc0e398f61e670bfeea81105cbe098294e39ac566e1d5aa7232df741870ba1fe96e5cede8372ca587275d35c1a5d1b23a11e274a4c249afba03e20fa2dafb7a16eebdf6%3A1476373826753; _iuqxldmzr_=25; _ntes_nnid=7fa73e96706f26f3ada99abba6c4a6b2,1476372027128; _ntes_nuid=7fa73e96706f26f3ada99abba6c4a6b2; __utma=94650624.748605760.1476372027.1476372027.1476372027.1; __utmb=94650624.4.10.1476372027; __utmc=94650624; __utmz=94650624.1476372027.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)',
}
params = {
'csrf_token': ''
}
data = {
'params': '5L+s/X1qDy33tb2sjT6to2T4oxv89Fjg1aYRkjgzpNPR6hgCpp0YVjNoTLQAwWu9VYvKROPZQj6qTpBK+sUeJovyNHsnU9/StEfZwCOcKfECFFtAvoNIpulj1TDOtBir',
'encSecKey': '59079f3e07d6e240410018dc871bf9364f122b720c0735837d7916ac78d48a79ec06c6307e6a0e576605d6228bd0b377a96e1a7fc7c7ddc8f6a3dc6cc50746933352d4ec5cbe7bddd6dcb94de085a3b408d895ebfdf2f43a7c72fc783512b3c9efb860679a88ef21ccec5ff13592be450a1edebf981c0bf779b122ddbd825492'
}
offset = 0
music_id = '516997458'
url = 'http://music.163.com/api/v1/resource/comments/R_SO_4_'+ music_id + '?limit=20&offset=' + str(offset)
print(url)
http://music.163.com/api/v1/resource/comments/R_SO_4_516997458?limit=20&offset=0
offset = 0
music_id = '516997458'
url = 'http://music.163.com/api/v1/resource/comments/R_SO_4_'+ music_id + '?limit=20&offset=' + str(offset)
response = requests.post(url, headers=headers, data=data)
cj = response.json()
cj.keys()
dict_keys(['total', 'more', 'moreHot', 'hotComments', 'userId', 'topComments', 'comments', 'isMusician', 'code'])
cj['hotComments']
[{'beReplied': [], 'commentId': 605012425, 'commentLocationType': 1, 'content': '合作很开心 \\(//∇//)\\ 再强调一下 不要比较哦~', 'decoration': None, 'expressionUrl': None, 'liked': False, 'likedCount': 31474, 'parentCommentId': 0, 'pendantData': None, 'repliedMark': False, 'showFloorComment': None, 'status': 0, 'time': 1509773639514, 'user': {'authStatus': 1, 'avatarUrl': 'http://p2.music.126.net/DOm76SPCQKRbQT9Y9uhwrA==/109951163717598478.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': '双笙子', 'remarkName': None, 'userId': 135214753, 'userType': 4, 'vipRights': None, 'vipType': 0}}, {'beReplied': [], 'commentId': 605186129, 'commentLocationType': 0, 'content': '2017.02.27,我鼓起勇气私信了二笙,希望能听到她翻唱《白石溪》,于是,2017.11.04,我得偿所愿,疯狂打call!!!', 'decoration': None, 'expressionUrl': None, 'liked': False, 'likedCount': 18512, 'parentCommentId': 0, 'pendantData': None, 'repliedMark': False, 'showFloorComment': None, 'status': 0, 'time': 1509785241690, 'user': {'authStatus': 0, 'avatarUrl': 'http://p2.music.126.net/RUYiHbkMH-oynQm_hjXyDw==/18915998044379216.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': '我就是猴子啊', 'remarkName': None, 'userId': 136088330, 'userType': 0, 'vipRights': {'associator': {'rights': True, 'vipCode': 100}, 'musicPackage': None, 'redVipAnnualCount': 1}, 'vipType': 11}}, {'beReplied': [], 'commentId': 606532743, 'commentLocationType': 0, 'content': '他年君归,我已白首,可否安否?[心碎]', 'decoration': None, 'expressionUrl': None, 'liked': False, 'likedCount': 9525, 'parentCommentId': 0, 'pendantData': None, 'repliedMark': False, 'showFloorComment': None, 'status': 0, 'time': 1509890451139, 'user': {'authStatus': 1, 'avatarUrl': 'http://p2.music.126.net/DT1H8k8UZKF-IifM2fzdHg==/109951163850082224.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': '左启文', 'remarkName': None, 'userId': 573597989, 'userType': 4, 'vipRights': None, 'vipType': 0}}, {'beReplied': [], 'commentId': 605144328, 'commentLocationType': 0, 'content': '为笙不离古风 敢问东风,玉成双偶!', 'decoration': None, 'expressionUrl': None, 'liked': False, 'likedCount': 7793, 'parentCommentId': 0, 'pendantData': None, 'repliedMark': False, 'showFloorComment': None, 'status': 0, 'time': 1509782850774, 'user': {'authStatus': 1, 'avatarUrl': 'http://p2.music.126.net/KmOtNRZ5_ToYyvYE3K4txw==/109951163539808902.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': '小月萧要抱抱', 'remarkName': None, 'userId': 511241074, 'userType': 4, 'vipRights': None, 'vipType': 0}}, {'beReplied': [], 'commentId': 606375014, 'commentLocationType': 0, 'content': '此生相依,人间白首。', 'decoration': None, 'expressionUrl': None, 'liked': False, 'likedCount': 5772, 'parentCommentId': 0, 'pendantData': {'id': 4002, 'imageUrl': 'http://p1.music.126.net/yMXwThrlR-9EB8m-xCwJTQ==/109951163313135573.jpg'}, 'repliedMark': False, 'showFloorComment': None, 'status': 0, 'time': 1509879397234, 'user': {'authStatus': 1, 'avatarUrl': 'http://p2.music.126.net/DuX4kYdk6iD5-m0EPeod-A==/1393081243116509.jpg', 'expertTags': None, 'experts': {'1': '音乐原创视频达人', '2': '古风资讯达人'}, 'locationInfo': None, 'nickname': '叶洛洛_', 'remarkName': None, 'userId': 41575131, 'userType': 4, 'vipRights': {'associator': {'rights': True, 'vipCode': 100}, 'musicPackage': None, 'redVipAnnualCount': 1}, 'vipType': 11}}, {'beReplied': [], 'commentId': 605045551, 'commentLocationType': 0, 'content': '遗君一心 一心怎收?@双笙子', 'decoration': None, 'expressionUrl': None, 'liked': False, 'likedCount': 4203, 'parentCommentId': 0, 'pendantData': None, 'repliedMark': False, 'showFloorComment': None, 'status': 0, 'time': 1509775953038, 'user': {'authStatus': 0, 'avatarUrl': 'http://p2.music.126.net/q-F0hEb7fbhXIc24Id6k8g==/109951163824141936.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': '-Taroty-', 'remarkName': None, 'userId': 253884140, 'userType': 0, 'vipRights': {'associator': {'rights': True, 'vipCode': 100}, 'musicPackage': None, 'redVipAnnualCount': -1}, 'vipType': 11}}, {'beReplied': [{'beRepliedCommentId': 605012425, 'content': '合作很开心 \\(//∇//)\\ 再强调一下 不要比较哦~', 'expressionUrl': None, 'status': 0, 'user': {'authStatus': 1, 'avatarUrl': 'http://p2.music.126.net/DOm76SPCQKRbQT9Y9uhwrA==/109951163717598478.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': '双笙子', 'remarkName': None, 'userId': 135214753, 'userType': 4, 'vipRights': None, 'vipType': 0}}], 'commentId': 605025286, 'commentLocationType': 0, 'content': '好!!!超温柔好喜欢啊!!', 'decoration': None, 'expressionUrl': None, 'liked': False, 'likedCount': 3469, 'parentCommentId': 0, 'pendantData': None, 'repliedMark': False, 'showFloorComment': None, 'status': 0, 'time': 1509773949545, 'user': {'authStatus': 0, 'avatarUrl': 'http://p2.music.126.net/n3zDytKxsEn7o73-hghrOg==/109951163907894797.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': '再看要给钱的', 'remarkName': None, 'userId': 117723916, 'userType': 0, 'vipRights': None, 'vipType': 0}}, {'beReplied': [], 'commentId': 605179520, 'commentLocationType': 0, 'content': '“金风玉露一相逢,便胜却人间无数” “身无彩凤双飞翼,心有灵犀一点通” 笙,最近真的高产呐~表白你♡♡我最好的二笙♡月月的声音也好听的不要不要的♡为我的两个女神打call~冬季了过的都好吧?♡♡☆', 'decoration': None, 'expressionUrl': None, 'liked': False, 'likedCount': 2716, 'parentCommentId': 0, 'pendantData': None, 'repliedMark': False, 'showFloorComment': None, 'status': 0, 'time': 1509785525844, 'user': {'authStatus': 0, 'avatarUrl': 'http://p2.music.126.net/mjqnDgYQqyNQr0NTRLrhBg==/109951163658952918.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': '慕小然呐', 'remarkName': None, 'userId': 454717946, 'userType': 0, 'vipRights': {'associator': None, 'musicPackage': {'rights': True, 'vipCode': 220}, 'redVipAnnualCount': -1}, 'vipType': 10}}, {'beReplied': [], 'commentId': 605412277, 'commentLocationType': 0, 'content': '大家不要再捞那个评论了,也不用举报了。开开心心听歌,好的坏的评论都接收,不接收恶意揣测和胡乱分析。最新出的《不立传》是原创同人曲,《扬州姑娘》是人声本家,《飞行安全颂》是和银临女神的合作曲,《羽人夜歌》还有《女孩你为何踮脚尖》同样是原唱和人声本家。', 'decoration': None, 'expressionUrl': None, 'liked': False, 'likedCount': 2532, 'parentCommentId': 0, 'pendantData': None, 'repliedMark': False, 'showFloorComment': None, 'status': 0, 'time': 1509799538380, 'user': {'authStatus': 0, 'avatarUrl': 'http://p2.music.126.net/RoyBWg89m_6QWNSrb8pK-A==/109951163860176383.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': '嘎吱____', 'remarkName': None, 'userId': 272211992, 'userType': 0, 'vipRights': None, 'vipType': 0}}, {'beReplied': [], 'commentId': 607843027, 'commentLocationType': 0, 'content': '发现双笙长大了不带囧菌一起玩了。。。。', 'decoration': None, 'expressionUrl': None, 'liked': False, 'likedCount': 2032, 'parentCommentId': 0, 'pendantData': None, 'repliedMark': False, 'showFloorComment': None, 'status': 0, 'time': 1510027128236, 'user': {'authStatus': 0, 'avatarUrl': 'http://p2.music.126.net/CSt7VwgL3eN8OZtQW9Y0Mw==/18800549325165207.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': '草丛里好多水', 'remarkName': None, 'userId': 377560577, 'userType': 0, 'vipRights': None, 'vipType': 0}}, {'beReplied': [], 'commentId': 605158591, 'commentLocationType': 0, 'content': '白石溪畔 斜阳逐流,可嫌 金风玉露 兼程久,灵犀心念 便相谋。只羡鸳鸯不羡仙,你是我心里的琴瑟和鸣,在我眼底你那么好,白首偕老,隔首相望,忆昔盼兮。@双笙子 ', 'decoration': None, 'expressionUrl': None, 'liked': False, 'likedCount': 1471, 'parentCommentId': 0, 'pendantData': None, 'repliedMark': False, 'showFloorComment': None, 'status': 0, 'time': 1509784001095, 'user': {'authStatus': 0, 'avatarUrl': 'http://p2.music.126.net/-I1R0pArRrY8etmreIeKpA==/109951163911256830.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': '煮酒溫涼為锣故', 'remarkName': None, 'userId': 351891558, 'userType': 0, 'vipRights': {'associator': {'rights': True, 'vipCode': 100}, 'musicPackage': None, 'redVipAnnualCount': -1}, 'vipType': 11}}, {'beReplied': [], 'commentId': 605388801, 'commentLocationType': 0, 'content': '冥月小姐姐唱到 何年夕何,两相执手 的时候突然的低音简直温柔的让我心头一颤!实在是太好听啦!还有小双笙的蜜汁少年音!(2333)和冥月小姐姐唱到 九霄一曲 人间白首,隔世相问 忆否忆否。那里简直不能太配了!希望以后两位女神能多多合作出些更多的古风歌!❤️❤️[亲亲][亲亲]', 'decoration': None, 'expressionUrl': None, 'liked': False, 'likedCount': 1413, 'parentCommentId': 0, 'pendantData': None, 'repliedMark': False, 'showFloorComment': None, 'status': 0, 'time': 1509799104012, 'user': {'authStatus': 0, 'avatarUrl': 'http://p2.music.126.net/PfBFxqykfk4_B0RU6b3JYg==/109951163547476225.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': '瓜君身下的可爱傲娇高冷攻orz', 'remarkName': None, 'userId': 397792954, 'userType': 0, 'vipRights': None, 'vipType': 0}}, {'beReplied': [], 'commentId': 605353067, 'commentLocationType': 0, 'content': '后排表白二笙[亲亲][亲亲]顺带表白全员[亲]每个歌手都会唱出属于自己特点的歌,每个翻唱也只是演绎了令一个版本。我们都要不比不刷[大笑]做好自己,好好听歌[憨笑]继续表白我高产的二笙[爱心][爱心]我们会一直支持你的[亲亲][亲亲]', 'decoration': None, 'expressionUrl': None, 'liked': False, 'likedCount': 1122, 'parentCommentId': 0, 'pendantData': None, 'repliedMark': False, 'showFloorComment': None, 'status': 0, 'time': 1509796178459, 'user': {'authStatus': 0, 'avatarUrl': 'http://p2.music.126.net/odzoJ-TPYYnQQOjQQw6Reg==/19099616486559044.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': '忘忆羡泪', 'remarkName': None, 'userId': 540357008, 'userType': 0, 'vipRights': None, 'vipType': 0}}, {'beReplied': [], 'commentId': 605370392, 'commentLocationType': 0, 'content': '共笙, 百年暮昏,到白昼。', 'decoration': None, 'expressionUrl': None, 'liked': False, 'likedCount': 887, 'parentCommentId': 0, 'pendantData': None, 'repliedMark': False, 'showFloorComment': None, 'status': 0, 'time': 1509797619854, 'user': {'authStatus': 0, 'avatarUrl': 'http://p2.music.126.net/68DTrNOBb0w1pcd03tXY-A==/109951163586635183.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': '一袭白衣殒', 'remarkName': None, 'userId': 340825017, 'userType': 0, 'vipRights': None, 'vipType': 0}}, {'beReplied': [], 'commentId': 621427493, 'commentLocationType': 0, 'content': '人的一生,要死去三次。第一次,当你的心跳停止,呼吸消逝,你在生物学上被宣告了死亡;第二次,当你下葬,人们穿着黑衣出席你的葬礼,他们宣告,你在这个社会上不复存在,你悄然离去;而第三次死亡,是这个世界上最后一个记得你的人,把你忘记,于是,你就真正地死去。整个宇宙都将不再和你有关', 'decoration': None, 'expressionUrl': None, 'liked': False, 'likedCount': 667, 'parentCommentId': 0, 'pendantData': None, 'repliedMark': False, 'showFloorComment': None, 'status': 0, 'time': 1511352258015, 'user': {'authStatus': 0, 'avatarUrl': 'http://p2.music.126.net/hGZWQMTVju4Ise4O9Ifszw==/109951163918333368.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': '一起落入的那些俗套其实都很开心', 'remarkName': None, 'userId': 353580314, 'userType': 0, 'vipRights': {'associator': None, 'musicPackage': {'rights': True, 'vipCode': 220}, 'redVipAnnualCount': -1}, 'vipType': 10}}]
import random
import time
#from fake_useragent import UserAgent
offset = 0
musiccomment = []
for k, i in enumerate(jj.keys()):
#time.sleep(0.1+random.random())
#ua = UserAgent()
#headers['User-Agent'] = ua.random
url = 'http://music.163.com/api/v1/resource/comments/R_SO_4_'+ i+ '?limit=20&offset=' + str(offset)
#time.sleep(1.0+random.random())
response = requests.post(url, headers=headers, data=data)
cj = response.json()
flushprint(k)
if cj['hotComments']:
for items in cj['hotComments']:
mc = items['content']
musiccomment.append(mc)
elif cj['comments']:
for items in cj['comments']:
mc = items['content']
musiccomment.append(mc)
#except Exception as e:
# print(e)
# print(i)
if k % 100 ==0 and k != 0:
with open('comment0.txt', 'a+',encoding='utf-8') as f:
f.write(str(musiccomment)+'\n\n\n\n')
print('保存到了%d'%k)
musiccomment = []
100保存到了100 200保存到了200 300保存到了300 400保存到了400 500保存到了500 600保存到了600 700保存到了700 800保存到了800 900保存到了900 1000保存到了1000 1100保存到了1100 1200保存到了1200 1300保存到了1300 1400保存到了1400 1500保存到了1500 1600保存到了1600 1700保存到了1700 1800保存到了1800 1900保存到了1900 2000保存到了2000 2100保存到了2100 2200保存到了2200 2300保存到了2300 2400保存到了2400 2500保存到了2500 2600保存到了2600 2700保存到了2700 2800保存到了2800 2900保存到了2900 3000保存到了3000 3100保存到了3100 3200保存到了3200 3300保存到了3300 3400保存到了3400 3500保存到了3500 3600保存到了3600 3700保存到了3700 3800保存到了3800 3900保存到了3900 4000保存到了4000 4100保存到了4100 4200保存到了4200 4300保存到了4300 4400保存到了4400 4500保存到了4500 4600保存到了4600 4700保存到了4700 4800保存到了4800 4900保存到了4900 5000保存到了5000 5100保存到了5100 5200保存到了5200 5300保存到了5300 5400保存到了5400 5500保存到了5500 5600保存到了5600 5700保存到了5700 5800保存到了5800 5900保存到了5900 6000保存到了6000 6100保存到了6100 6200保存到了6200 6300保存到了6300 6400保存到了6400 6500保存到了6500 6600保存到了6600 6700保存到了6700 6800保存到了6800 6900保存到了6900 7000保存到了7000 7100保存到了7100 7200保存到了7200 7300保存到了7300 7400保存到了7400 7500保存到了7500 7600保存到了7600 7700保存到了7700 7800保存到了7800 7900保存到了7900 8000保存到了8000 8100保存到了8100 8200保存到了8200 8300保存到了8300 8400保存到了8400 8500保存到了8500 8600保存到了8600 8700保存到了8700 8800保存到了8800 8900保存到了8900 8981
--------------------------------------------------------------------------- KeyError Traceback (most recent call last) <ipython-input-9-18b37e92748d> in <module>() 22 23 ---> 24 if cj['hotComments']: 25 for items in cj['hotComments']: 26 mc = items['content'] KeyError: 'hotComments'
offset = 0
music_id = '516997458'
url = 'http://music.163.com/api/v1/resource/comments/R_SO_4_'+ music_id + '?limit=20&offset=' + str(offset)
response = requests.post(url, headers=headers, data=data)
cj = response.json()
cj.keys()
dict_keys(['code', 'msg'])
cj['comments']
[{'beReplied': [], 'commentId': 1429664496, 'commentLocationType': 0, 'content': '一个轻柔一个清澈,很好啊', 'decoration': {}, 'expressionUrl': None, 'isRemoveHotComment': False, 'liked': False, 'likedCount': 1, 'parentCommentId': 0, 'pendantData': None, 'repliedMark': False, 'showFloorComment': None, 'status': 0, 'time': 1553415176852, 'user': {'authStatus': 0, 'avatarUrl': 'http://p1.music.126.net/QwmQnU7NISJMojoDkethwQ==/109951163598132517.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': '梦想长高10厘米', 'remarkName': None, 'userId': 1635948673, 'userType': 0, 'vipRights': None, 'vipType': 0}}, {'beReplied': [{'beRepliedCommentId': 1429535389, 'content': '在你发评论的时候动动脑子,没有父母这话是随便说的吗,不了解就瞎喷[怒]', 'expressionUrl': None, 'status': 0, 'user': {'authStatus': 0, 'avatarUrl': 'http://p1.music.126.net/ro-GK-5XWK0BRS1SFaOQOw==/109951163932462029.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': 'Whisky2005', 'remarkName': None, 'userId': 1292353868, 'userType': 0, 'vipRights': None, 'vipType': 0}}], 'commentId': 1429714606, 'commentLocationType': 0, 'content': '别理她,举报就好', 'decoration': {}, 'expressionUrl': None, 'isRemoveHotComment': False, 'liked': False, 'likedCount': 0, 'parentCommentId': 1419676965, 'pendantData': None, 'repliedMark': False, 'showFloorComment': None, 'status': 0, 'time': 1553414969099, 'user': {'authStatus': 0, 'avatarUrl': 'http://p1.music.126.net/QwmQnU7NISJMojoDkethwQ==/109951163598132517.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': '梦想长高10厘米', 'remarkName': None, 'userId': 1635948673, 'userType': 0, 'vipRights': None, 'vipType': 0}}, {'beReplied': [{'beRepliedCommentId': 1429576231, 'content': '我也是姓左的', 'expressionUrl': None, 'status': 0, 'user': {'authStatus': 0, 'avatarUrl': 'http://p1.music.126.net/TizCd9qJuPOeTV7RiMvySA==/109951163872407610.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': '碧蓝丶丢人萌新', 'remarkName': None, 'userId': 538236549, 'userType': 0, 'vipRights': None, 'vipType': 0}}], 'commentId': 1429678839, 'commentLocationType': 0, 'content': 'qiao', 'decoration': {}, 'expressionUrl': None, 'isRemoveHotComment': False, 'liked': False, 'likedCount': 0, 'parentCommentId': 606532743, 'pendantData': None, 'repliedMark': False, 'showFloorComment': None, 'status': 0, 'time': 1553413811692, 'user': {'authStatus': 1, 'avatarUrl': 'http://p1.music.126.net/DT1H8k8UZKF-IifM2fzdHg==/109951163850082224.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': '左启文', 'remarkName': None, 'userId': 573597989, 'userType': 4, 'vipRights': None, 'vipType': 0}}, {'beReplied': [{'beRepliedCommentId': 1429535389, 'content': '在你发评论的时候动动脑子,没有父母这话是随便说的吗,不了解就瞎喷[怒]', 'expressionUrl': None, 'status': 0, 'user': {'authStatus': 0, 'avatarUrl': 'http://p2.music.126.net/ro-GK-5XWK0BRS1SFaOQOw==/109951163932462029.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': 'Whisky2005', 'remarkName': None, 'userId': 1292353868, 'userType': 0, 'vipRights': None, 'vipType': 0}}], 'commentId': 1429623280, 'commentLocationType': 0, 'content': '不想被喷就在说话前动动脑子,你说的这话就好像在说临摹得比原作还要好', 'decoration': {}, 'expressionUrl': None, 'isRemoveHotComment': False, 'liked': False, 'likedCount': 0, 'parentCommentId': 1419676965, 'pendantData': None, 'repliedMark': False, 'showFloorComment': None, 'status': 0, 'time': 1553412181764, 'user': {'authStatus': 0, 'avatarUrl': 'http://p2.music.126.net/Vlsfe2DBecxMOmVUPxYAlQ==/109951163106299956.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': '抱走哪个好呢', 'remarkName': None, 'userId': 624231369, 'userType': 0, 'vipRights': None, 'vipType': 0}}, {'beReplied': [], 'commentId': 1429657548, 'commentLocationType': 0, 'content': '好听', 'decoration': {}, 'expressionUrl': None, 'isRemoveHotComment': False, 'liked': False, 'likedCount': 0, 'parentCommentId': 0, 'pendantData': {'id': 5000, 'imageUrl': 'http://p1.music.126.net/11rU3itRKssu9iI-ly_hOQ==/109951163313124195.jpg'}, 'repliedMark': False, 'showFloorComment': None, 'status': 0, 'time': 1553411567807, 'user': {'authStatus': 0, 'avatarUrl': 'http://p2.music.126.net/6QUDHgG09dfyCUpddcg1aA==/109951163923068764.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': '____薛洋____', 'remarkName': None, 'userId': 1296734356, 'userType': 0, 'vipRights': {'associator': {'rights': True, 'vipCode': 100}, 'musicPackage': None, 'redVipAnnualCount': 1}, 'vipType': 11}}, {'beReplied': [{'beRepliedCommentId': 1429561582, 'content': '每个人有每个人的观点,何必互相喷呢,我就是认为比原版好听', 'expressionUrl': None, 'status': 0, 'user': {'authStatus': 0, 'avatarUrl': 'http://p2.music.126.net/ro-GK-5XWK0BRS1SFaOQOw==/109951163932462029.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': 'Whisky2005', 'remarkName': None, 'userId': 1292353868, 'userType': 0, 'vipRights': None, 'vipType': 0}}], 'commentId': 1429651603, 'commentLocationType': 0, 'content': '那我的评论也是在发表我的观点,臭👶👶', 'decoration': {}, 'expressionUrl': None, 'isRemoveHotComment': False, 'liked': False, 'likedCount': 0, 'parentCommentId': 1419676965, 'pendantData': None, 'repliedMark': False, 'showFloorComment': None, 'status': 0, 'time': 1553411505259, 'user': {'authStatus': 0, 'avatarUrl': 'http://p2.music.126.net/Vlsfe2DBecxMOmVUPxYAlQ==/109951163106299956.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': '抱走哪个好呢', 'remarkName': None, 'userId': 624231369, 'userType': 0, 'vipRights': None, 'vipType': 0}}, {'beReplied': [{'beRepliedCommentId': 1429535389, 'content': '在你发评论的时候动动脑子,没有父母这话是随便说的吗,不了解就瞎喷[怒]', 'expressionUrl': None, 'status': 0, 'user': {'authStatus': 0, 'avatarUrl': 'http://p2.music.126.net/ro-GK-5XWK0BRS1SFaOQOw==/109951163932462029.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': 'Whisky2005', 'remarkName': None, 'userId': 1292353868, 'userType': 0, 'vipRights': None, 'vipType': 0}}], 'commentId': 1429619101, 'commentLocationType': 0, 'content': '模仿的能超过原唱?你的脑子在哪?', 'decoration': {}, 'expressionUrl': None, 'isRemoveHotComment': False, 'liked': False, 'likedCount': 0, 'parentCommentId': 1419676965, 'pendantData': None, 'repliedMark': False, 'showFloorComment': None, 'status': 0, 'time': 1553411314670, 'user': {'authStatus': 0, 'avatarUrl': 'http://p2.music.126.net/Vlsfe2DBecxMOmVUPxYAlQ==/109951163106299956.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': '抱走哪个好呢', 'remarkName': None, 'userId': 624231369, 'userType': 0, 'vipRights': None, 'vipType': 0}}, {'beReplied': [{'beRepliedCommentId': 1429535389, 'content': '在你发评论的时候动动脑子,没有父母这话是随便说的吗,不了解就瞎喷[怒]', 'expressionUrl': None, 'status': 0, 'user': {'authStatus': 0, 'avatarUrl': 'http://p2.music.126.net/ro-GK-5XWK0BRS1SFaOQOw==/109951163932462029.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': 'Whisky2005', 'remarkName': None, 'userId': 1292353868, 'userType': 0, 'vipRights': None, 'vipType': 0}}], 'commentId': 1429626899, 'commentLocationType': 0, 'content': '你比较不就是踩一捧一?', 'decoration': {}, 'expressionUrl': None, 'isRemoveHotComment': False, 'liked': False, 'likedCount': 0, 'parentCommentId': 1419676965, 'pendantData': None, 'repliedMark': False, 'showFloorComment': None, 'status': 0, 'time': 1553411202358, 'user': {'authStatus': 0, 'avatarUrl': 'http://p2.music.126.net/Vlsfe2DBecxMOmVUPxYAlQ==/109951163106299956.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': '抱走哪个好呢', 'remarkName': None, 'userId': 624231369, 'userType': 0, 'vipRights': None, 'vipType': 0}}, {'beReplied': [{'beRepliedCommentId': 1429535389, 'content': '在你发评论的时候动动脑子,没有父母这话是随便说的吗,不了解就瞎喷[怒]', 'expressionUrl': None, 'status': 0, 'user': {'authStatus': 0, 'avatarUrl': 'http://p2.music.126.net/ro-GK-5XWK0BRS1SFaOQOw==/109951163932462029.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': 'Whisky2005', 'remarkName': None, 'userId': 1292353868, 'userType': 0, 'vipRights': None, 'vipType': 0}}], 'commentId': 1429615121, 'commentLocationType': 0, 'content': '说你怎么?', 'decoration': {}, 'expressionUrl': None, 'isRemoveHotComment': False, 'liked': False, 'likedCount': 0, 'parentCommentId': 1419676965, 'pendantData': None, 'repliedMark': False, 'showFloorComment': None, 'status': 0, 'time': 1553411128186, 'user': {'authStatus': 0, 'avatarUrl': 'http://p2.music.126.net/Vlsfe2DBecxMOmVUPxYAlQ==/109951163106299956.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': '抱走哪个好呢', 'remarkName': None, 'userId': 624231369, 'userType': 0, 'vipRights': None, 'vipType': 0}}, {'beReplied': [{'beRepliedCommentId': 1429224319, 'content': '对啊', 'expressionUrl': None, 'status': 0, 'user': {'authStatus': 1, 'avatarUrl': 'http://p2.music.126.net/DT1H8k8UZKF-IifM2fzdHg==/109951163850082224.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': '左启文', 'remarkName': None, 'userId': 573597989, 'userType': 4, 'vipRights': None, 'vipType': 0}}], 'commentId': 1429576231, 'commentLocationType': 0, 'content': '我也是姓左的', 'decoration': {}, 'expressionUrl': None, 'isRemoveHotComment': False, 'liked': False, 'likedCount': 0, 'parentCommentId': 606532743, 'pendantData': None, 'repliedMark': False, 'showFloorComment': None, 'status': 0, 'time': 1553409735409, 'user': {'authStatus': 0, 'avatarUrl': 'http://p2.music.126.net/TizCd9qJuPOeTV7RiMvySA==/109951163872407610.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': '碧蓝丶丢人萌新', 'remarkName': None, 'userId': 538236549, 'userType': 0, 'vipRights': None, 'vipType': 0}}, {'beReplied': [{'beRepliedCommentId': 1429125510, 'content': None, 'expressionUrl': None, 'status': -10, 'user': {'authStatus': 0, 'avatarUrl': 'http://p2.music.126.net/Vlsfe2DBecxMOmVUPxYAlQ==/109951163106299956.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': '抱走哪个好呢', 'remarkName': None, 'userId': 624231369, 'userType': 0, 'vipRights': None, 'vipType': 0}}], 'commentId': 1429535389, 'commentLocationType': 0, 'content': '在你发评论的时候动动脑子,没有父母这话是随便说的吗,不了解就瞎喷[怒]', 'decoration': {}, 'expressionUrl': None, 'isRemoveHotComment': False, 'liked': False, 'likedCount': 0, 'parentCommentId': 1419676965, 'pendantData': None, 'repliedMark': False, 'showFloorComment': None, 'status': 0, 'time': 1553407382977, 'user': {'authStatus': 0, 'avatarUrl': 'http://p2.music.126.net/ro-GK-5XWK0BRS1SFaOQOw==/109951163932462029.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': 'Whisky2005', 'remarkName': None, 'userId': 1292353868, 'userType': 0, 'vipRights': None, 'vipType': 0}}, {'beReplied': [{'beRepliedCommentId': 1419676965, 'content': '比原版还好听', 'expressionUrl': None, 'status': 0, 'user': {'authStatus': 0, 'avatarUrl': 'http://p2.music.126.net/ro-GK-5XWK0BRS1SFaOQOw==/109951163932462029.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': 'Whisky2005', 'remarkName': None, 'userId': 1292353868, 'userType': 0, 'vipRights': None, 'vipType': 0}}], 'commentId': 1429537210, 'commentLocationType': 0, 'content': '还有我只是说这比原版好听,也没有贬低原版的意思,原版已经很好听但这个版本我觉的比原版更好听', 'decoration': {}, 'expressionUrl': None, 'isRemoveHotComment': False, 'liked': False, 'likedCount': 0, 'parentCommentId': 1419676965, 'pendantData': None, 'repliedMark': False, 'showFloorComment': None, 'status': 0, 'time': 1553407042602, 'user': {'authStatus': 0, 'avatarUrl': 'http://p2.music.126.net/ro-GK-5XWK0BRS1SFaOQOw==/109951163932462029.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': 'Whisky2005', 'remarkName': None, 'userId': 1292353868, 'userType': 0, 'vipRights': None, 'vipType': 0}}, {'beReplied': [{'beRepliedCommentId': 1419676965, 'content': '比原版还好听', 'expressionUrl': None, 'status': 0, 'user': {'authStatus': 0, 'avatarUrl': 'http://p2.music.126.net/ro-GK-5XWK0BRS1SFaOQOw==/109951163932462029.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': 'Whisky2005', 'remarkName': None, 'userId': 1292353868, 'userType': 0, 'vipRights': None, 'vipType': 0}}], 'commentId': 1429561582, 'commentLocationType': 0, 'content': '每个人有每个人的观点,何必互相喷呢,我就是认为比原版好听', 'decoration': {}, 'expressionUrl': None, 'isRemoveHotComment': False, 'liked': False, 'likedCount': 0, 'parentCommentId': 1419676965, 'pendantData': None, 'repliedMark': False, 'showFloorComment': None, 'status': 0, 'time': 1553406518992, 'user': {'authStatus': 0, 'avatarUrl': 'http://p2.music.126.net/ro-GK-5XWK0BRS1SFaOQOw==/109951163932462029.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': 'Whisky2005', 'remarkName': None, 'userId': 1292353868, 'userType': 0, 'vipRights': None, 'vipType': 0}}, {'beReplied': [], 'commentId': 1429269929, 'commentLocationType': 0, 'content': '竹业篇而来\n霸业未有妻,淮竹终为妾,一生挚爱,不离不弃,即使没有相思树,我也相信,有情人会再次重聚。', 'decoration': {}, 'expressionUrl': None, 'isRemoveHotComment': False, 'liked': False, 'likedCount': 1, 'parentCommentId': 0, 'pendantData': None, 'repliedMark': False, 'showFloorComment': None, 'status': 0, 'time': 1553391403396, 'user': {'authStatus': 0, 'avatarUrl': 'http://p2.music.126.net/MTLZ68_k-sK3UO4W5_5ucQ==/109951163603755384.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': '银河中的妖精', 'remarkName': None, 'userId': 1534534690, 'userType': 0, 'vipRights': {'associator': {'rights': True, 'vipCode': 100}, 'musicPackage': None, 'redVipAnnualCount': -1}, 'vipType': 11}}, {'beReplied': [{'beRepliedCommentId': 1428723383, 'content': '左启文是你的真名吗?', 'expressionUrl': None, 'status': 0, 'user': {'authStatus': 0, 'avatarUrl': 'http://p2.music.126.net/TizCd9qJuPOeTV7RiMvySA==/109951163872407610.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': '碧蓝丶丢人萌新', 'remarkName': None, 'userId': 538236549, 'userType': 0, 'vipRights': None, 'vipType': 0}}], 'commentId': 1429224319, 'commentLocationType': 0, 'content': '对啊', 'decoration': {}, 'expressionUrl': None, 'isRemoveHotComment': False, 'liked': False, 'likedCount': 0, 'parentCommentId': 606532743, 'pendantData': None, 'repliedMark': False, 'showFloorComment': None, 'status': 0, 'time': 1553389865376, 'user': {'authStatus': 1, 'avatarUrl': 'http://p2.music.126.net/DT1H8k8UZKF-IifM2fzdHg==/109951163850082224.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': '左启文', 'remarkName': None, 'userId': 573597989, 'userType': 4, 'vipRights': None, 'vipType': 0}}, {'beReplied': [], 'commentId': 1429054997, 'commentLocationType': 0, 'content': '好听,幸福', 'decoration': {}, 'expressionUrl': None, 'isRemoveHotComment': False, 'liked': False, 'likedCount': 0, 'parentCommentId': 0, 'pendantData': None, 'repliedMark': False, 'showFloorComment': None, 'status': 0, 'time': 1553357795390, 'user': {'authStatus': 0, 'avatarUrl': 'http://p2.music.126.net/x6SwELtUm6EnwdnCe-BpuQ==/109951163633064303.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': '朱晓含', 'remarkName': None, 'userId': 302073820, 'userType': 0, 'vipRights': None, 'vipType': 0}}, {'beReplied': [{'beRepliedCommentId': 1426851758, 'content': '我说为什么他们总说双笙粉,今天终于看到活了', 'expressionUrl': None, 'status': 0, 'user': {'authStatus': 0, 'avatarUrl': 'http://p2.music.126.net/4ooxbFU4X-5ZH3aigGt8Cg==/109951163736134599.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': '泠沄洨', 'remarkName': None, 'userId': 1709480639, 'userType': 0, 'vipRights': None, 'vipType': 0}}], 'commentId': 1429019611, 'commentLocationType': 0, 'content': '素质烂的可以 招黑还不知收敛 ', 'decoration': {}, 'expressionUrl': None, 'isRemoveHotComment': False, 'liked': False, 'likedCount': 0, 'parentCommentId': 1419676965, 'pendantData': None, 'repliedMark': False, 'showFloorComment': None, 'status': 0, 'time': 1553355337359, 'user': {'authStatus': 0, 'avatarUrl': 'http://p2.music.126.net/pkfMbRlEIrFyVXRaSfiRUA==/109951163169252433.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': '落尘之土', 'remarkName': None, 'userId': 1386034882, 'userType': 0, 'vipRights': None, 'vipType': 0}}, {'beReplied': [{'beRepliedCommentId': 607843027, 'content': '发现双笙长大了不带囧菌一起玩了。。。。', 'expressionUrl': None, 'status': 0, 'user': {'authStatus': 0, 'avatarUrl': 'http://p2.music.126.net/CSt7VwgL3eN8OZtQW9Y0Mw==/18800549325165207.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': '草丛里好多水', 'remarkName': None, 'userId': 377560577, 'userType': 0, 'vipRights': None, 'vipType': 0}}], 'commentId': 1428965499, 'commentLocationType': 0, 'content': '靠别人捧红还踩别人', 'decoration': {}, 'expressionUrl': None, 'isRemoveHotComment': False, 'liked': False, 'likedCount': 0, 'parentCommentId': 607843027, 'pendantData': None, 'repliedMark': False, 'showFloorComment': None, 'status': 0, 'time': 1553355298319, 'user': {'authStatus': 0, 'avatarUrl': 'http://p2.music.126.net/pkfMbRlEIrFyVXRaSfiRUA==/109951163169252433.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': '落尘之土', 'remarkName': None, 'userId': 1386034882, 'userType': 0, 'vipRights': None, 'vipType': 0}}, {'beReplied': [], 'commentId': 1428841216, 'commentLocationType': 0, 'content': '所谓伊人,在水一方\n所谓君子,望而欲求\n君子问曰,可期三年\n伊人对曰,可期朝夕', 'decoration': {}, 'expressionUrl': None, 'isRemoveHotComment': False, 'liked': False, 'likedCount': 2, 'parentCommentId': 0, 'pendantData': None, 'repliedMark': False, 'showFloorComment': None, 'status': 0, 'time': 1553349527069, 'user': {'authStatus': 0, 'avatarUrl': 'http://p2.music.126.net/eZvGVQERWKkWkQgPiXhRiw==/109951163789573760.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': '琛宝波特', 'remarkName': None, 'userId': 1462458458, 'userType': 0, 'vipRights': None, 'vipType': 0}}, {'beReplied': [{'beRepliedCommentId': 606532743, 'content': '他年君归,我已白首,可否安否?[心碎]', 'expressionUrl': None, 'status': 0, 'user': {'authStatus': 1, 'avatarUrl': 'http://p2.music.126.net/DT1H8k8UZKF-IifM2fzdHg==/109951163850082224.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': '左启文', 'remarkName': None, 'userId': 573597989, 'userType': 4, 'vipRights': None, 'vipType': 0}}], 'commentId': 1428723383, 'commentLocationType': 0, 'content': '左启文是你的真名吗?', 'decoration': {}, 'expressionUrl': None, 'isRemoveHotComment': False, 'liked': False, 'likedCount': 0, 'parentCommentId': 606532743, 'pendantData': None, 'repliedMark': False, 'showFloorComment': None, 'status': 0, 'time': 1553344533467, 'user': {'authStatus': 0, 'avatarUrl': 'http://p2.music.126.net/TizCd9qJuPOeTV7RiMvySA==/109951163872407610.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': '碧蓝丶丢人萌新', 'remarkName': None, 'userId': 538236549, 'userType': 0, 'vipRights': None, 'vipType': 0}}]
cj['hotComments']
[{'beReplied': [], 'commentId': 605012425, 'commentLocationType': 1, 'content': '合作很开心 \\(//∇//)\\ 再强调一下 不要比较哦~', 'decoration': None, 'expressionUrl': None, 'liked': False, 'likedCount': 31460, 'parentCommentId': 0, 'pendantData': None, 'repliedMark': False, 'showFloorComment': None, 'status': 0, 'time': 1509773639514, 'user': {'authStatus': 1, 'avatarUrl': 'http://p2.music.126.net/DOm76SPCQKRbQT9Y9uhwrA==/109951163717598478.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': '双笙子', 'remarkName': None, 'userId': 135214753, 'userType': 4, 'vipRights': None, 'vipType': 0}}, {'beReplied': [], 'commentId': 605186129, 'commentLocationType': 0, 'content': '2017.02.27,我鼓起勇气私信了二笙,希望能听到她翻唱《白石溪》,于是,2017.11.04,我得偿所愿,疯狂打call!!!', 'decoration': None, 'expressionUrl': None, 'liked': False, 'likedCount': 18503, 'parentCommentId': 0, 'pendantData': None, 'repliedMark': False, 'showFloorComment': None, 'status': 0, 'time': 1509785241690, 'user': {'authStatus': 0, 'avatarUrl': 'http://p2.music.126.net/RUYiHbkMH-oynQm_hjXyDw==/18915998044379216.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': '我就是猴子啊', 'remarkName': None, 'userId': 136088330, 'userType': 0, 'vipRights': {'associator': {'rights': True, 'vipCode': 100}, 'musicPackage': None, 'redVipAnnualCount': 1}, 'vipType': 11}}, {'beReplied': [], 'commentId': 606532743, 'commentLocationType': 0, 'content': '他年君归,我已白首,可否安否?[心碎]', 'decoration': None, 'expressionUrl': None, 'liked': False, 'likedCount': 9524, 'parentCommentId': 0, 'pendantData': None, 'repliedMark': False, 'showFloorComment': None, 'status': 0, 'time': 1509890451139, 'user': {'authStatus': 1, 'avatarUrl': 'http://p2.music.126.net/DT1H8k8UZKF-IifM2fzdHg==/109951163850082224.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': '左启文', 'remarkName': None, 'userId': 573597989, 'userType': 4, 'vipRights': None, 'vipType': 0}}, {'beReplied': [], 'commentId': 605144328, 'commentLocationType': 0, 'content': '为笙不离古风 敢问东风,玉成双偶!', 'decoration': None, 'expressionUrl': None, 'liked': False, 'likedCount': 7792, 'parentCommentId': 0, 'pendantData': None, 'repliedMark': False, 'showFloorComment': None, 'status': 0, 'time': 1509782850774, 'user': {'authStatus': 1, 'avatarUrl': 'http://p2.music.126.net/KmOtNRZ5_ToYyvYE3K4txw==/109951163539808902.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': '小月萧要抱抱', 'remarkName': None, 'userId': 511241074, 'userType': 4, 'vipRights': None, 'vipType': 0}}, {'beReplied': [], 'commentId': 606375014, 'commentLocationType': 0, 'content': '此生相依,人间白首。', 'decoration': None, 'expressionUrl': None, 'liked': False, 'likedCount': 5770, 'parentCommentId': 0, 'pendantData': {'id': 4002, 'imageUrl': 'http://p1.music.126.net/yMXwThrlR-9EB8m-xCwJTQ==/109951163313135573.jpg'}, 'repliedMark': False, 'showFloorComment': None, 'status': 0, 'time': 1509879397234, 'user': {'authStatus': 1, 'avatarUrl': 'http://p2.music.126.net/DuX4kYdk6iD5-m0EPeod-A==/1393081243116509.jpg', 'expertTags': None, 'experts': {'1': '音乐原创视频达人', '2': '古风资讯达人'}, 'locationInfo': None, 'nickname': '叶洛洛_', 'remarkName': None, 'userId': 41575131, 'userType': 4, 'vipRights': {'associator': {'rights': True, 'vipCode': 100}, 'musicPackage': None, 'redVipAnnualCount': 1}, 'vipType': 11}}, {'beReplied': [], 'commentId': 605045551, 'commentLocationType': 0, 'content': '遗君一心 一心怎收?@双笙子', 'decoration': None, 'expressionUrl': None, 'liked': False, 'likedCount': 4203, 'parentCommentId': 0, 'pendantData': None, 'repliedMark': False, 'showFloorComment': None, 'status': 0, 'time': 1509775953038, 'user': {'authStatus': 0, 'avatarUrl': 'http://p2.music.126.net/q-F0hEb7fbhXIc24Id6k8g==/109951163824141936.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': '-Taroty-', 'remarkName': None, 'userId': 253884140, 'userType': 0, 'vipRights': {'associator': {'rights': True, 'vipCode': 100}, 'musicPackage': None, 'redVipAnnualCount': -1}, 'vipType': 11}}, {'beReplied': [{'beRepliedCommentId': 605012425, 'content': '合作很开心 \\(//∇//)\\ 再强调一下 不要比较哦~', 'expressionUrl': None, 'status': 0, 'user': {'authStatus': 1, 'avatarUrl': 'http://p2.music.126.net/DOm76SPCQKRbQT9Y9uhwrA==/109951163717598478.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': '双笙子', 'remarkName': None, 'userId': 135214753, 'userType': 4, 'vipRights': None, 'vipType': 0}}], 'commentId': 605025286, 'commentLocationType': 0, 'content': '好!!!超温柔好喜欢啊!!', 'decoration': None, 'expressionUrl': None, 'liked': False, 'likedCount': 3469, 'parentCommentId': 0, 'pendantData': None, 'repliedMark': False, 'showFloorComment': None, 'status': 0, 'time': 1509773949545, 'user': {'authStatus': 0, 'avatarUrl': 'http://p2.music.126.net/n3zDytKxsEn7o73-hghrOg==/109951163907894797.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': '再看要给钱的', 'remarkName': None, 'userId': 117723916, 'userType': 0, 'vipRights': None, 'vipType': 0}}, {'beReplied': [], 'commentId': 605179520, 'commentLocationType': 0, 'content': '“金风玉露一相逢,便胜却人间无数” “身无彩凤双飞翼,心有灵犀一点通” 笙,最近真的高产呐~表白你♡♡我最好的二笙♡月月的声音也好听的不要不要的♡为我的两个女神打call~冬季了过的都好吧?♡♡☆', 'decoration': None, 'expressionUrl': None, 'liked': False, 'likedCount': 2716, 'parentCommentId': 0, 'pendantData': None, 'repliedMark': False, 'showFloorComment': None, 'status': 0, 'time': 1509785525844, 'user': {'authStatus': 0, 'avatarUrl': 'http://p2.music.126.net/mjqnDgYQqyNQr0NTRLrhBg==/109951163658952918.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': '慕小然呐', 'remarkName': None, 'userId': 454717946, 'userType': 0, 'vipRights': {'associator': None, 'musicPackage': {'rights': True, 'vipCode': 220}, 'redVipAnnualCount': -1}, 'vipType': 10}}, {'beReplied': [], 'commentId': 605412277, 'commentLocationType': 0, 'content': '大家不要再捞那个评论了,也不用举报了。开开心心听歌,好的坏的评论都接收,不接收恶意揣测和胡乱分析。最新出的《不立传》是原创同人曲,《扬州姑娘》是人声本家,《飞行安全颂》是和银临女神的合作曲,《羽人夜歌》还有《女孩你为何踮脚尖》同样是原唱和人声本家。', 'decoration': None, 'expressionUrl': None, 'liked': False, 'likedCount': 2532, 'parentCommentId': 0, 'pendantData': None, 'repliedMark': False, 'showFloorComment': None, 'status': 0, 'time': 1509799538380, 'user': {'authStatus': 0, 'avatarUrl': 'http://p2.music.126.net/RoyBWg89m_6QWNSrb8pK-A==/109951163860176383.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': '嘎吱____', 'remarkName': None, 'userId': 272211992, 'userType': 0, 'vipRights': None, 'vipType': 0}}, {'beReplied': [], 'commentId': 607843027, 'commentLocationType': 0, 'content': '发现双笙长大了不带囧菌一起玩了。。。。', 'decoration': None, 'expressionUrl': None, 'liked': False, 'likedCount': 2027, 'parentCommentId': 0, 'pendantData': None, 'repliedMark': False, 'showFloorComment': None, 'status': 0, 'time': 1510027128236, 'user': {'authStatus': 0, 'avatarUrl': 'http://p2.music.126.net/CSt7VwgL3eN8OZtQW9Y0Mw==/18800549325165207.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': '草丛里好多水', 'remarkName': None, 'userId': 377560577, 'userType': 0, 'vipRights': None, 'vipType': 0}}, {'beReplied': [], 'commentId': 605158591, 'commentLocationType': 0, 'content': '白石溪畔 斜阳逐流,可嫌 金风玉露 兼程久,灵犀心念 便相谋。只羡鸳鸯不羡仙,你是我心里的琴瑟和鸣,在我眼底你那么好,白首偕老,隔首相望,忆昔盼兮。@双笙子 ', 'decoration': None, 'expressionUrl': None, 'liked': False, 'likedCount': 1470, 'parentCommentId': 0, 'pendantData': None, 'repliedMark': False, 'showFloorComment': None, 'status': 0, 'time': 1509784001095, 'user': {'authStatus': 0, 'avatarUrl': 'http://p2.music.126.net/-I1R0pArRrY8etmreIeKpA==/109951163911256830.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': '煮酒溫涼為锣故', 'remarkName': None, 'userId': 351891558, 'userType': 0, 'vipRights': {'associator': {'rights': True, 'vipCode': 100}, 'musicPackage': None, 'redVipAnnualCount': -1}, 'vipType': 11}}, {'beReplied': [], 'commentId': 605388801, 'commentLocationType': 0, 'content': '冥月小姐姐唱到 何年夕何,两相执手 的时候突然的低音简直温柔的让我心头一颤!实在是太好听啦!还有小双笙的蜜汁少年音!(2333)和冥月小姐姐唱到 九霄一曲 人间白首,隔世相问 忆否忆否。那里简直不能太配了!希望以后两位女神能多多合作出些更多的古风歌!❤️❤️[亲亲][亲亲]', 'decoration': None, 'expressionUrl': None, 'liked': False, 'likedCount': 1411, 'parentCommentId': 0, 'pendantData': None, 'repliedMark': False, 'showFloorComment': None, 'status': 0, 'time': 1509799104012, 'user': {'authStatus': 0, 'avatarUrl': 'http://p2.music.126.net/PfBFxqykfk4_B0RU6b3JYg==/109951163547476225.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': '瓜君身下的可爱傲娇高冷攻orz', 'remarkName': None, 'userId': 397792954, 'userType': 0, 'vipRights': None, 'vipType': 0}}, {'beReplied': [], 'commentId': 605353067, 'commentLocationType': 0, 'content': '后排表白二笙[亲亲][亲亲]顺带表白全员[亲]每个歌手都会唱出属于自己特点的歌,每个翻唱也只是演绎了令一个版本。我们都要不比不刷[大笑]做好自己,好好听歌[憨笑]继续表白我高产的二笙[爱心][爱心]我们会一直支持你的[亲亲][亲亲]', 'decoration': None, 'expressionUrl': None, 'liked': False, 'likedCount': 1122, 'parentCommentId': 0, 'pendantData': None, 'repliedMark': False, 'showFloorComment': None, 'status': 0, 'time': 1509796178459, 'user': {'authStatus': 0, 'avatarUrl': 'http://p2.music.126.net/odzoJ-TPYYnQQOjQQw6Reg==/19099616486559044.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': '忘忆羡泪', 'remarkName': None, 'userId': 540357008, 'userType': 0, 'vipRights': None, 'vipType': 0}}, {'beReplied': [], 'commentId': 605370392, 'commentLocationType': 0, 'content': '共笙, 百年暮昏,到白昼。', 'decoration': None, 'expressionUrl': None, 'liked': False, 'likedCount': 887, 'parentCommentId': 0, 'pendantData': None, 'repliedMark': False, 'showFloorComment': None, 'status': 0, 'time': 1509797619854, 'user': {'authStatus': 0, 'avatarUrl': 'http://p2.music.126.net/68DTrNOBb0w1pcd03tXY-A==/109951163586635183.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': '一袭白衣殒', 'remarkName': None, 'userId': 340825017, 'userType': 0, 'vipRights': None, 'vipType': 0}}, {'beReplied': [], 'commentId': 621427493, 'commentLocationType': 0, 'content': '人的一生,要死去三次。第一次,当你的心跳停止,呼吸消逝,你在生物学上被宣告了死亡;第二次,当你下葬,人们穿着黑衣出席你的葬礼,他们宣告,你在这个社会上不复存在,你悄然离去;而第三次死亡,是这个世界上最后一个记得你的人,把你忘记,于是,你就真正地死去。整个宇宙都将不再和你有关', 'decoration': None, 'expressionUrl': None, 'liked': False, 'likedCount': 667, 'parentCommentId': 0, 'pendantData': None, 'repliedMark': False, 'showFloorComment': None, 'status': 0, 'time': 1511352258015, 'user': {'authStatus': 0, 'avatarUrl': 'http://p2.music.126.net/hGZWQMTVju4Ise4O9Ifszw==/109951163918333368.jpg', 'expertTags': None, 'experts': None, 'locationInfo': None, 'nickname': '一起落入的那些俗套其实都很开心', 'remarkName': None, 'userId': 353580314, 'userType': 0, 'vipRights': {'associator': None, 'musicPackage': {'rights': True, 'vipCode': 220}, 'redVipAnnualCount': -1}, 'vipType': 10}}]
http://music.163.com/api/v1/resource/comments/R_SO_4_516997458?limit=20&offset=0
cj['total'],len(cj['comments']), len(cj['hotComments']), len(cj['topComments'])
(9220, 20, 15, 0)
musiccomment = []
for items in cj['hotComments']:
mc = items['content']
musiccomment.append(mc)
with open('comment.txt', 'a+',encoding='utf-8') as f:
f.write(str(musiccomment)+'\n')
musiccomment = []
cj['hotComments'][0]['content']
'合作很开心 \\(//∇//)\\ 再强调一下 不要比较哦~'