用python获取易班文章评论信息
Lan
2020-04-21 09:16
304 人阅读
0 条评论
import requests
url = 'https://www.yiban.cn/forum/reply/listAjax'
headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36',
}
data = {
'channel_id': '289081',
'puid': '13088902',
'article_id': '121116137',
'page': '1',
'size': '200',
'order': '1',
}
html = requests.post(headers=headers, data=data, url=url).json()
data = html['data']['list']
content = []
floor = []
createTime = []
name = []
nameid = []
nick = []
counts = len(data)
for i in range(counts - 1):
commen = data[str(i)]
con = commen['content']
content.append(str(con).replace('\n', ''))
floor.append(commen['floor'])
createTime.append(commen['createTime'])
name.append(commen['user']['name'])
nameid.append(commen['user']['id'])
nick.append(commen['user']['nick'])
with open('result.csv', 'a+',encoding='utf-') as f:
f.write('姓名}用户id}昵称}楼层}评论时间}评论内容')
for i in range(len(name)):
f.write(
name[i] + "}" + nameid[i] + "}" + nick[i] + "}" + floor[i] + "}" + createTime[i] + "}" + content[i] + "\n")
赞赏