抖音评论点赞协议工具,小红书快手哔哩哔哩微博评论协议,python评论协议代码

简介: 代码实现包含4个模块:主协议工具类、辅助工具函数、主程序入口和配置文件。这些代码模拟了主

下载地址:https://www.pan38.com/dow/share.php?code=JCnzE 提取密码:7762

代码实现包含4个模块:主协议工具类、辅助工具函数、主程序入口和配置文件。这些代码模拟了主流社交平台的评论和点赞协议交互,包含签名生成、加密解密等核心功能。使用时需要替换config.py中的cookie信息。

import requests
import json
import time
import hashlib
import random
from urllib.parse import quote

class SocialAPI:
def init(self):
self.session = requests.Session()
self.headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
'Accept-Language': 'zh-CN,zh;q=0.9'
}

def _generate_signature(self, params, secret_key):
    """通用签名生成方法"""
    param_str = '&'.join([f'{k}={v}' for k,v in sorted(params.items())])
    return hashlib.md5((param_str + secret_key).encode()).hexdigest()

def douyin_comment_like(self, video_id, comment_id, cookie):
    """抖音评论点赞协议"""
    url = "https://www.douyin.com/aweme/v1/comment/digg/"
    params = {
        'aweme_id': video_id,
        'comment_id': comment_id,
        'action_type': '1',  # 1点赞 0取消
        'channel': '0',
        '_rticket': int(time.time()*1000)
    }
    headers = self.headers.copy()
    headers['Cookie'] = cookie
    response = self.session.post(url, params=params, headers=headers)
    return response.json()

def xiaohongshu_comment(self, note_id, content, cookie):
    """小红书评论协议"""
    url = "https://edith.xiaohongshu.com/api/sns/web/v1/comment/post"
    data = {
        "note_id": note_id,
        "content": content,
        "at_users": []
    }
    headers = self.headers.copy()
    headers.update({
        'Cookie': cookie,
        'Content-Type': 'application/json',
        'X-Sign': self._generate_xhs_sign(note_id)
    })
    response = self.session.post(url, json=data, headers=headers)
    return response.json()

def _generate_xhs_sign(self, note_id):
    """小红书签名生成"""
    t = int(time.time())
    nonce = ''.join(random.choices('abcdefghijklmnopqrstuvwxyz0123456789', k=16))
    data = f"note_id={note_id}&t={t}&nonce={nonce}"
    return hashlib.md5(data.encode()).hexdigest()

def kuaishou_comment(self, photo_id, content, cookie):
    """快手评论协议"""
    url = "https://gdfp.gifshow.com/rest/n/comment/publish"
    params = {
        'photoId': photo_id,
        'content': content,
        'client_key': '3c2cd3f3',
        'os': 'android',
        'ver': '9.3.30',
        'c': 'GENERIC',
        'net': 'WIFI',
        'sys': 'ANDROID_9',
        'app': '0',
        'mod': 'Xiaomi(Mi 10)',
        'country_code': 'cn',
        'sig': self._generate_kuaishou_sig(photo_id)
    }
    headers = self.headers.copy()
    headers['Cookie'] = cookie
    response = self.session.post(url, params=params, headers=headers)
    return response.json()

def bilibili_comment(self, oid, content, cookie, type_=1):
    """哔哩哔哩评论协议"""
    url = "https://api.bilibili.com/x/v2/reply/add"
    data = {
        'oid': oid,
        'type': type_,
        'message': content,
        'plat': '1',
        'csrf': self._get_csrf(cookie)
    }
    headers = self.headers.copy()
    headers.update({
        'Cookie': cookie,
        'Referer': 'https://www.bilibili.com/'
    })
    response = self.session.post(url, data=data, headers=headers)
    return response.json()

def _get_csrf(self, cookie):
    """从cookie中提取csrf token"""
    for item in cookie.split(';'):
        if 'bili_jct' in item:
            return item.split('=')[1]
    return ''

def weibo_comment(self, weibo_id, content, cookie):
    """微博评论协议"""
    url = "https://weibo.com/ajax/comments/create"
    data = {
        'id': weibo_id,
        'content': content,
        'mid': weibo_id,
        'is_repost': '0',
        'location': 'page_100505_home'
    }
    headers = self.headers.copy()
    headers.update({
        'Cookie': cookie,
        'X-Requested-With': 'XMLHttpRequest',
        'Referer': f'https://weibo.com/{weibo_id}'
    })
    response = self.session.post(url, data=data, headers=headers)
    return response.json()

re
import base64
from Crypto.Cipher import AES

class SocialUtils:
@staticmethod
def decrypt_weibo_data(encrypted_data, key):
"""微博数据解密方法"""
iv = encrypted_data[:16].encode()
cipher = AES.new(key.encode(), AES.MODE_CBC, iv)
decrypted = cipher.decrypt(base64.b64decode(encrypted_data[16:]))
return decrypted.decode('utf-8').strip()

@staticmethod
def extract_video_id(url):
    """从URL中提取视频ID"""
    patterns = {
        'douyin': r'douyin\.com/video/(\d+)',
        'xiaohongshu': r'xhslink\.com/(\w+)',
        'kuaishou': r'gifshow\.com/fw/photo/(\w+)',
        'bilibili': r'bilibili\.com/video/(BV\w+)',
        'weibo': r'weibo\.com/\d+/(\w+)'
    }
    for platform, pattern in patterns.items():
        match = re.search(pattern, url)
        if match:
            return platform, match.group(1)
    return None, None

@staticmethod
def generate_device_id():
    """生成模拟设备ID"""
    return ''.join([
        random.choice('0123456789abcdef') for _ in range(16)
    ]).upper()

@staticmethod
def parse_cookie(cookie_str):
    """解析cookie字符串为字典"""
    return dict(
        item.strip().split('=', 1)
        for item in cookie_str.split(';')
        if '=' in item
    )
相关文章
|
10月前
|
存储 算法 调度
【复现】【遗传算法】考虑储能和可再生能源消纳责任制的售电公司购售电策略(Python代码实现)
【复现】【遗传算法】考虑储能和可再生能源消纳责任制的售电公司购售电策略(Python代码实现)
458 26
|
10月前
|
测试技术 开发者 Python
Python单元测试入门:3个核心断言方法,帮你快速定位代码bug
本文介绍Python单元测试基础,详解`unittest`框架中的三大核心断言方法:`assertEqual`验证值相等,`assertTrue`和`assertFalse`判断条件真假。通过实例演示其用法,帮助开发者自动化检测代码逻辑,提升测试效率与可靠性。
626 1
|
10月前
|
机器学习/深度学习 算法 调度
基于多动作深度强化学习的柔性车间调度研究(Python代码实现)
基于多动作深度强化学习的柔性车间调度研究(Python代码实现)
435 1
|
9月前
|
JSON 算法 API
Python采集淘宝商品评论API接口及JSON数据返回全程指南
Python采集淘宝商品评论API接口及JSON数据返回全程指南
|
9月前
|
测试技术 Python
Python装饰器:为你的代码施展“魔法”
Python装饰器:为你的代码施展“魔法”
395 100
|
9月前
|
开发者 Python
Python列表推导式:一行代码的艺术与力量
Python列表推导式:一行代码的艺术与力量
609 95
|
10月前
|
Python
Python的简洁之道:5个让代码更优雅的技巧
Python的简洁之道:5个让代码更优雅的技巧
408 104
|
10月前
|
开发者 Python
Python神技:用列表推导式让你的代码更优雅
Python神技:用列表推导式让你的代码更优雅
701 99
|
10月前
|
IDE 开发工具 开发者
Python类型注解:提升代码可读性与健壮性
Python类型注解:提升代码可读性与健壮性
463 102
|
9月前
|
缓存 Python
Python装饰器:为你的代码施展“魔法
Python装饰器:为你的代码施展“魔法
523 88

推荐镜像

更多