贴吧私信自动群发神器,百度贴吧群发批量私信脚本插件,python框架分享

简介: 这个贴吧私信群发工具包含三个主要文件:主程序、配置文件和入口文件。主程序实现了登录

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

这个贴吧私信群发工具包含三个主要文件:主程序、配置文件和入口文件。主程序实现了登录、获取好友列表、发送私信等核心功能,并加入了防封策略。使用时请遵守贴吧规则,合理设置发送频率和数量。

import requests
import time
import random
import json
from bs4 import BeautifulSoup
import re
import os
import hashlib
from fake_useragent import UserAgent

class TiebaSpammer:
def init(self, username, password):
self.session = requests.Session()
self.ua = UserAgent()
self.username = username
self.password = password
self.cookies = None
self.headers = {
'User-Agent': self.ua.random,
'Referer': 'https://tieba.baidu.com/',
'Host': 'tieba.baidu.com',
'Connection': 'keep-alive'
}
self.login_url = 'https://passport.baidu.com/v2/api/?login'
self.message_url = 'https://tieba.baidu.com/mo/q/newmoindex'
self.token_pattern = re.compile(r"name='token' value='(.*?)'")
self.captcha_url = 'https://passport.baidu.com/cgi-bin/genimage?'

def login(self):
    # 获取登录token
    login_page = self.session.get('https://passport.baidu.com/v2/api/?getapi&tpl=mn&apiver=v3')
    token_match = self.token_pattern.search(login_page.text)
    if not token_match:
        raise Exception("获取token失败")
    token = token_match.group(1)

    # 构造登录参数
    login_data = {
        'username': self.username,
        'password': self.password,
        'token': token,
        'tpl': 'mn',
        'apiver': 'v3',
        'tt': str(int(time.time() * 1000)),
        'codestring': '',
        'isPhone': 'false',
        'staticpage': 'https://passport.baidu.com/static/passpc-account/html/v3Jump.html',
        'loginType': '1',
        'callback': 'parent.bd__pcbs__ra48vi'
    }

    # 发送登录请求
    response = self.session.post(self.login_url, data=login_data, headers=self.headers)
    if 'err_no=0' in response.text:
        print("登录成功")
        self.cookies = response.cookies.get_dict()
        return True
    else:
        print("登录失败:", response.text)
        return False

def get_friends_list(self, page=1):
    friends = []
    params = {
        'pn': page,
        'type': 'friend'
    }
    response = self.session.get('https://tieba.baidu.com/mo/q/contact/list', params=params, headers=self.headers)
    soup = BeautifulSoup(response.text, 'html.parser')
    items = soup.find_all('div', class_='list_item')
    for item in items:
        name = item.find('span', class_='name').text.strip()
        uid = item.find('input', {'name': 'uid'})['value']
        friends.append({'name': name, 'uid': uid})
    return friends

def send_private_message(self, uid, content):
    data = {
        'content': content,
        'to_uid': uid,
        'from_uid': '',
        'fid': '',
        'tid': '',
        'type': '1',
        'anonymous': '0',
        'is_comment': '0'
    }
    response = self.session.post(self.message_url, data=data, headers=self.headers)
    if response.json().get('err_no') == 0:
        print(f"发送成功: {uid}")
        return True
    else:
        print(f"发送失败: {response.text}")
        return False

def batch_send_messages(self, uids, content, delay=5, max_per_day=50):
    sent_count = 0
    for uid in uids:
        if sent_count >= max_per_day:
            print("达到每日发送上限")
            break

        if self.send_private_message(uid, content):
            sent_count += 1
            sleep_time = delay + random.uniform(-1, 1)
            print(f"等待 {sleep_time:.2f} 秒后继续...")
            time.sleep(sleep_time)

def anti_ban_strategy(self):
    # 随机更换User-Agent
    self.headers['User-Agent'] = self.ua.random
    # 随机延迟
    time.sleep(random.uniform(1, 3))
    # 随机访问其他页面
    random_page = random.choice(['https://tieba.baidu.com/f?kw=%E7%99%BE%E5%BA%A6', 
                               'https://tieba.baidu.com/f?kw=python'])
    self.session.get(random_page, headers=self.headers)

def run(self, message_content, max_friends=100):
    if not self.login():
        return

    all_friends = []
    page = 1
    while len(all_friends) < max_friends:
        friends = self.get_friends_list(page)
        if not friends:
            break
        all_friends.extend(friends)
        page += 1
        time.sleep(2)

    print(f"获取到 {len(all_friends)} 个好友")
    uids = [friend['uid'] for friend in all_friends[:max_friends]]
    self.batch_send_messages(uids, message_content)
相关文章
|
1月前
|
JSON 算法 API
深度分析小红书城API接口,用Python脚本实现
小红书作为以UGC内容为核心的生活方式平台,其非官方API主要通过移动端抓包解析获得,涵盖内容推荐、搜索、笔记详情、用户信息和互动操作等功能。本文分析了其接口体系、认证机制及请求规范,并提供基于Python的调用框架,涉及签名生成、登录态管理与数据解析。需注意非官方接口存在稳定性与合规风险,使用时应遵守平台协议及法律法规。
|
1月前
|
JSON API 数据安全/隐私保护
【干货满满】分享微店API接口到手价,用python脚本实现
微店作为知名社交电商平台,其开放平台提供商品查询、订单管理等API接口。本文介绍如何通过微店API获取商品到手价(含优惠、券等),涵盖认证机制、Python实现及关键说明。
|
1月前
|
JSON API 数据格式
深度分析大麦网API接口,用Python脚本实现
大麦网为国内领先演出票务平台,提供演唱会、话剧、体育赛事等票务服务。本文基于抓包分析其非官方接口,并提供Python调用方案,涵盖演出列表查询、详情获取及城市列表获取。需注意非官方接口存在稳定性风险,使用时应遵守平台规则,控制请求频率,防范封禁与法律风险。适用于个人学习、演出信息监控等场景。
|
26天前
|
机器学习/深度学习 算法 PyTorch
【Pytorch框架搭建神经网络】基于DQN算法、优先级采样的DQN算法、DQN + 人工势场的避障控制研究(Python代码实现)
【Pytorch框架搭建神经网络】基于DQN算法、优先级采样的DQN算法、DQN + 人工势场的避障控制研究(Python代码实现)
|
1月前
|
JSON API 开发者
深度分析阿里妈妈API接口,用Python脚本实现
阿里妈妈是阿里巴巴旗下营销平台,提供淘宝联盟、直通车等服务,支持推广位管理、商品查询等API功能。本文详解其API调用方法,重点实现商品推广信息(佣金、优惠券)获取,并提供Python实现方案。
|
19天前
|
机器学习/深度学习 算法 PyTorch
【DQN实现避障控制】使用Pytorch框架搭建神经网络,基于DQN算法、优先级采样的DQN算法、DQN + 人工势场实现避障控制研究(Matlab、Python实现)
【DQN实现避障控制】使用Pytorch框架搭建神经网络,基于DQN算法、优先级采样的DQN算法、DQN + 人工势场实现避障控制研究(Matlab、Python实现)
|
1月前
|
API 数据安全/隐私保护 开发者
深度分析苏宁API接口,用Python脚本实现
深度分析苏宁API接口,用Python脚本实现
|
1月前
|
JSON API 数据安全/隐私保护
深度分析虾皮城API接口,用Python脚本实现
虾皮开放平台提供丰富的API接口,支持商品管理、订单处理及促销信息查询等功能。本文详解API认证机制与调用方法,基于Python实现商品价格及到手价获取方案,适用于电商数据分析与运营。
|
1月前
|
前端开发 Shell API
深度分析58同城API接口,用Python脚本实现
58同城为国内知名分类信息平台,涵盖房产、招聘、二手车等多领域。本文基于网页抓包与解析,分享其非官方接口的Python实现方案,分析核心接口特性与反爬应对策略,适用于数据学习与信息聚合。注意:非官方接口存在风险,使用需遵守平台规则。
|
11天前
|
数据采集 机器学习/深度学习 人工智能
Python:现代编程的首选语言
Python:现代编程的首选语言
183 102

推荐镜像

更多