import requests
import json
import time
class DouyinLiveCommentCrawler:
def __init__(self, live_id, access_token):
self.live_id = live_id
self.access_token = access_token
self.url = "https://api.douyin.com/aweme/v1/live/comments/"
self.params = {
"live_id": live_id,
"cursor": "0",
"count": "20"
}
self.headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3",
"Authorization": "Bearer " + access_token
}
def crawl_comments(self):
while True:
try:
response = requests.get(self.url, params=self.params, headers=self.headers, timeout=10)
response.raise_for_status()
except requests.exceptions.RequestException as e:
print("请求错误:", e)
time.sleep(5)
continue
data = json.loads(response.text)
if data["status_code"] != 0:
print("错误代码:", data["status_code"], "错误信息:", data["status_msg"])
break
for comment in data["comments"]:
print("评论用户:", comment["user"]["nickname"])
print("评论内容:", comment["text"])
print("评论时间:", comment["create_time"])
print("------------")
if data["has_more"] == 0:
break
self.params["cursor"] = data["cursor"]
time.sleep(1) # 速率限制,0.1秒爬取一次
if __name__ == "__main__":
live_id = "your_live_id"
access_token = "your_access_token"
crawler = DouyinLiveCommentCrawler(live_id, access_token)
crawler.crawl_comments()
抖音直播间工具箱
功能1:支持批量导入直播间链接采集 支持关键词搜索直播间进行采集(可过滤匿名)
功能2:访客进入直播间 动作 礼物 发言 昵称 等级 性别 地区 粉丝 等显示
功能3自动去重 单击可显示二维码主页 作品链接 粉丝 关注等
功能5:可进行多条件筛选匹配 显示精准 过滤无作品 私密账号 过滤性别等 匹配指定多地区 匹配多评论关键词
功能6:支持自动智能导出 支持继续过滤