练习---爬取QQ音乐某首歌的评论,并存入Excel表中---以《消愁》为例

本文介绍如何使用Python爬虫获取QQ音乐《消愁》这首歌的用户评论,并将数据整理存储到Excel表格中,涉及requests、BeautifulSoup和pandas库的使用。
摘要由CSDN通过智能技术生成
import requests
from bs4 import BeautifulSoup
import json
import xlwt

#存储成Excel表格的函数
def save_excel(comment,save_file):
#第一个参数的整个评论存储所在的列表
	wb=xlwt.Workbook()
	sheet=wb.add_sheet('评论')
	for i in range(len(comment)): #第i个评论列表
		for j in range(len(comment[i])):
			sheet.write(i,j,comment[i][j])
	wb.save('C:/Users/Xpeng/Desktop/爬取到的表格/'+save_file)

#----爬取QQ音乐某首歌(topid区分)的评论
def song_comment(topid):
	url='https://c.y.qq.com/base/fcgi-bin/fcg_global_comment_h5.fcg'
	comment_id=''
	all_com=[]
	for p in range(10):
		params={
		'g_tk':'5381',
		'loginUin':'943413047',
		'hostUin': '0',
		'format': 'json',
		'inCharset': 'utf8',
		'outCharset':'GB2312',
		'notice':'0',
		'platform':'yqq.json',
		'needNewCode':'0',
		'cid':&#
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值