马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
请教大神,我用论坛中的爬虫程序只获得了网易云中的一首歌的20条评论,请问可以获取全部评论吗?感谢~~~
import requests
import json
def get_comment(res):
comments_json = json.loads(res.text)
comments=comments_json['data']['comments']
with open('commments.txt','w',encoding='utf-8')as file:
for each in comments:
file.write(each['user']['nickname']+':\n\n')
file.write(each['content']+'\n')
file.write('---------------------------------------\n')
def get_url(url):
headers={'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3314.0 Safari/537.36 SE 2.X MetaSr 1.0',
'referer':'https://music.163.com/song?id=1435449062'}
params= 'r1GlVgogiUtKOTFQgUibWP7uulMmPIKIhpw8mI4E3N/s2LaCmLD8whPWY+kxwsBPXVI5l1d/Gb2q6jKagpIucGGZnFgNxEcmQNYWk+LxPk6MU0CvOfDTyXBviTIpXJT69E61/H1vluuYvP0QqdobvK9/lrhbtVaM20TMy/AmkPIX+DhTRJs6ilwza+bLDdrQCcnFV69Il/L0plP6YG7/zdsqPTl0kVb9fXSLFID3AvvS0R4kwi3Eg+49ACtGl6N0Hcr1UBmzw9fdBEfnsr7Ws65eXpMZ6WKMw7oBUSuTYZg='
encSecKey= 'd7ae3cb3961bbe48adc988202619a2da378a77107b4e4bb4dbc54685367e955f6e17a3b1d2881899de10b8fb2008de1c5549f2c605a3bac7b5d43dcde25a0e34d2edde250653c95e099de076ca0385106bd2c7beb74d3a1304039dfee811185e06d68dad4106c63bc321f90ea2cb3ccd83c1e24c1775021017fe8a41c0da60b9'
data={
'params':params,
'encSecKey':encSecKey
}
target_url='https://music.163.com/weapi/comment/resource/comments/get?csrf_token='
res= requests.post(target_url,headers=headers,data=data)
return res
def main():
url= input('please input the wangzhi:')
res= get_url(url)
get_comment(res)
if __name__=='__main__':
main()
|