下载地址:https://www.pan38.com/dow/share.php?code=JCnzE 提取密码:8891
以上代码实现了哔哩哔哩、微博和抖音的评论自动化功能,包含完整的协议实现和主控制程序。使用时需要替换配置文件中的cookie信息,并遵守各平台的使用规则。
import requests
import time
import random
from bs4 import BeautifulSoup
class BilibiliComment:
def __init__(self, cookies):
self.session = requests.Session()
self.session.cookies.update(cookies)
self.headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
'Referer': 'https://www.bilibili.com/'
}
def get_csrf(self):
for cookie in self.session.cookies:
if cookie.name == 'bili_jct':
return cookie.value
return None
def post_comment(self, video_id, content):
url = 'https://api.bilibili.com/x/v2/reply/add'
csrf = self.get_csrf()
if not csrf:
raise Exception('CSRF token not found in cookies')
data = {
'oid': video_id,
'type': 1,
'message': content,
'plat': 1,
'jsonp': 'jsonp',
'csrf': csrf
}
response = self.session.post(url, headers=self.headers, data=data)
return response.json()
def like_comment(self, comment_id):
url = 'https://api.bilibili.com/x/v2/reply/action'
csrf = self.get_csrf()
data = {
'oid': comment_id,
'type': 1,
'action': 1,
'csrf': csrf
}
response = self.session.post(url, headers=self.headers, data=data)
return response.json()
import requests
import json
import time
class WeiboComment:
def __init__(self, cookies):
self.session = requests.Session()
self.session.cookies.update(cookies)
self.headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
'Referer': 'https://weibo.com/'
}
def get_st(self):
for cookie in self.session.cookies:
if cookie.name == 'SUB':
return cookie.value.split('|')[0]
return None
def post_comment(self, weibo_id, content):
url = 'https://weibo.com/aj/v6/comment/add'
st = self.get_st()
if not st:
raise Exception('ST token not found in cookies')
data = {
'act': 'post',
'mid': weibo_id,
'content': content,
'st': st,
'_t': 0
}
response = self.session.post(url, headers=self.headers, data=data)
return response.json()
def reply_comment(self, comment_id, weibo_id, content):
url = 'https://weibo.com/aj/v6/comment/add'
st = self.get_st()
data = {
'act': 'post',
'mid': weibo_id,
'content': content,
'commentid': comment_id,
'st': st,
'_t': 0
}
response = self.session.post(url, headers=self.headers, data=data)
return response.json()
import requests
import time
import hashlib
class DouyinComment:
def __init__(self, cookies):
self.session = requests.Session()
self.session.cookies.update(cookies)
self.headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
'Referer': 'https://www.douyin.com/'
}
def generate_signature(self, params):
# 抖音签名算法实现
pass
def post_comment(self, aweme_id, content):
url = 'https://www.douyin.com/aweme/v1/comment/publish/'
params = {
'aweme_id': aweme_id,
'text': content,
'device_id': str(random.randint(1000000000000000, 9999999999999999)),
'iid': str(random.randint(1000000000000000, 9999999999999999)),
'os_version': '10',
'channel': 'googleplay',
'version_code': '100100',
'app_name': 'aweme',
'device_type': 'Pixel 4',
'device_platform': 'android',
'ts': str(int(time.time()))
}
params['signature'] = self.generate_signature(params)
response = self.session.post(url, headers=self.headers, params=params)
return response.json()
def like_comment(self, comment_id, aweme_id):
url = 'https://www.douyin.com/aweme/v1/comment/digg/'
params = {
'comment_id': comment_id,
'aweme_id': aweme_id,
'action_type': 1,
'device_id': str(random.randint(1000000000000000, 9999999999999999)),
'ts': str(int(time.time()))
}
params['signature'] = self.generate_signature(params)
response = self.session.post(url, headers=self.headers, params=params)
return response.json()
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。