贴吧私信群发工具,采集贴吧ID信息,批量群发贴吧私信插件

简介: 这个实现包含两个主要模块:用户ID采集和私信发送。采集模块通过解析贴吧页面获取用户ID

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

这个实现包含两个主要模块:用户ID采集和私信发送。采集模块通过解析贴吧页面获取用户ID,发送模块模拟用户操作发送私信。使用时需要注意:1.需要有效的百度cookie 2.发送频率不宜过高 3.内容应符合贴吧规定。

import requests
from bs4 import BeautifulSoup
import re
import time
import random

class TiebaUserSpider:
def init(self, tieba_name):
self.tieba_name = tieba_name
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'
}
self.user_list = set()

def get_page_users(self, page_num):
    url = f"https://tieba.baidu.com/f?kw={self.tieba_name}&pn={(page_num-1)*50}"
    try:
        response = requests.get(url, headers=self.headers)
        soup = BeautifulSoup(response.text, 'html.parser')
        user_links = soup.find_all('a', {'class': 'p_author_name'})

        for link in user_links:
            username = link.text.strip()
            if username not in self.user_list:
                self.user_list.add(username)

        print(f"第{page_num}页采集完成,共采集到{len(self.user_list)}个用户")
        time.sleep(random.uniform(1, 3))

    except Exception as e:
        print(f"采集第{page_num}页时出错: {str(e)}")

def run(self, start_page=1, end_page=10):
    for page in range(start_page, end_page+1):
        self.get_page_users(page)

    with open(f'{self.tieba_name}_users.txt', 'w', encoding='utf-8') as f:
        for user in self.user_list:
            f.write(user + '\n')

    print(f"采集完成,共采集到{len(self.user_list)}个用户,已保存到{self.tieba_name}_users.txt")

if name == 'main':
spider = TiebaUserSpider('python')
spider.run(1, 5)

requests
import time
import random
from fake_useragent import UserAgent

class TiebaMessageSender:
def init(self, cookie):
self.cookie = cookie
self.ua = UserAgent()
self.headers = {
'User-Agent': self.ua.random,
'Cookie': self.cookie,
'Referer': 'https://tieba.baidu.com/',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
}

def send_message(self, to_user, content):
    url = "https://tieba.baidu.com/msg/send"
    data = {
        'to_user': to_user,
        'content': content,
        'anonymous': '0',
        'is_comment': '0'
    }

    try:
        response = requests.post(url, headers=self.headers, data=data)
        result = response.json()

        if result.get('no') == 0:
            print(f"发送给{to_user}成功")
            return True
        else:
            print(f"发送给{to_user}失败: {result.get('error')}")
            return False

    except Exception as e:
        print(f"发送给{to_user}时出错: {str(e)}")
        return False

def batch_send(self, user_list_file, message, delay=5, max_retry=3):
    success_count = 0
    fail_count = 0

    with open(user_list_file, 'r', encoding='utf-8') as f:
        users = [line.strip() for line in f if line.strip()]

    for i, user in enumerate(users):
        retry = 0
        while retry < max_retry:
            if self.send_message(user, message):
                success_count += 1
                break
            else:
                retry += 1
                if retry == max_retry:
                    fail_count += 1

        if i < len(users) - 1:
            sleep_time = random.uniform(delay-1, delay+1)
            print(f"等待{sleep_time:.1f}秒后继续...")
            time.sleep(sleep_time)

    print(f"发送完成,成功{success_count}条,失败{fail_count}条")

if name == 'main':

# 需要替换为有效的百度cookie
cookie = "BDUSS=your_bduss_here;"
sender = TiebaMessageSender(cookie)
sender.batch_send('python_users.txt', '您好,这是一条测试消息', delay=10)
相关文章
|
4月前
|
JSON 机器人 数据安全/隐私保护
微信自动聊天机器人, 微信自动回复机器人,python框架分享
这个微信机器人实现包含主程序、配置文件、工具函数和测试脚本四个模块。主程序使用itchat库
|
4月前
|
存储 API 数据库
自动发短信的软件,批量自动群发短信,手机号电话号生成器【python框架】
这个短信群发系统包含以下核心功能: 随机手机号生成器(支持中国号码) 批量短信发送功能(使用Twilio API)
|
4月前
|
API 数据安全/隐私保护 Python
批量发短信的软件,自动群发短信批量工具,手机号电话生成脚本插件【python】
该工具包含三个核心模块:短信发送核心功能、配置管理系统和命令行界面。使用时需先配置API密钥和短信模板
|
4月前
|
机器学习/深度学习 数据安全/隐私保护 计算机视觉
过三色刷脸技术,过三色刷脸技术教程,插件过人脸python分享学习
三色刷脸技术是基于RGB三通道分离的人脸特征提取方法,通过分析人脸在不同颜色通道的特征差异
|
4月前
|
数据采集 Web App开发 JSON
微博采集评论区数据工具,微博爬取博主粉丝ID抓取,微博提取评论ID博主粉丝列表
这个代码实现了完整的微博数据采集功能,包括评论采集、粉丝ID抓取和评论用户粉丝列表获取
|
4月前
|
数据采集 数据处理 数据安全/隐私保护
小红书爬虫采集工具, 小红书截流获客软件,直播间评论作品提取软件
这个项目包含三个主要模块:爬虫核心、数据处理和代理管理。使用时需要安装requests
|
4月前
|
机器人 API 数据安全/隐私保护
QQ机器人插件源码,自动回复聊天机器人,python源码分享
消息接收处理:通过Flask搭建HTTP服务接收go-cqhttp推送的QQ消息47 智能回复逻辑
|
4月前
|
数据安全/隐私保护
小红书自动评论软件,小红书评论回复脚本,autojs框架分享
该脚本主要实现以下功能模块: 关键词触发机制
|
4月前
|
数据安全/隐私保护
贴吧自动发帖工具, 贴吧自动评论脚本,顶贴回复发帖插件
这个代码实现了贴吧自动发帖、自动回复、获取帖子列表等功能。主要使用了requests库进行网络请求
下一篇
oss云网关配置