阿里旺旺私信群发工具,淘宝商家私信群发软件,python代码分享

简介: 该代码实现了完整的淘宝旺旺群发流程,包含商品采集、消息模板定制和自动化发送功能

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

该代码实现了完整的淘宝旺旺群发流程,包含商品采集、消息模板定制和自动化发送功能。核心采用Selenium模拟浏览器操作,通过随机间隔和滚动加载提升稳定性17。商品筛选模块支持按价格和销量过滤,消息发送模块内置防封号机制,建议配合多账号轮换使用16。

技术要点说明:

采用面向对象设计,三大功能模块封装为独立方法
商品采集使用XPath定位元素,支持多页滚动加载
消息发送包含随机延迟和异常处理机制
配置文件集中管理关键参数,便于批量操作

import time
import random
import pandas as pd
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException

class TaobaoSpammer:
def init(self):
self.driver = webdriver.Chrome()
self.wait = WebDriverWait(self.driver, 15)
self.login_url = "https://login.taobao.com"
self.message_template = """
尊敬的商家您好:
【{product}】现特价仅需¥{price}!
点击直达:{link}
"""

def login(self, username, password):
    self.driver.get(self.login_url)
    try:
        self.wait.until(EC.presence_of_element_located((By.ID, "fm-login-id")))
        self.driver.find_element(By.ID, "fm-login-id").send_keys(username)
        self.driver.find_element(By.ID, "fm-login-password").send_keys(password)
        self.driver.find_element(By.CLASS_NAME, "password-login").click()
        time.sleep(random.uniform(3,5))
    except Exception as e:
        print(f"登录失败: {str(e)}")

def search_products(self, keyword, max_price=100, min_sales=50):
    search_url = f"https://s.taobao.com/search?q={keyword}"
    self.driver.get(search_url)
    products = []

    for _ in range(3):  # 滚动3页
        try:
            items = self.wait.until(
                EC.presence_of_all_elements_located((By.XPATH, '//div[@class="items"]/div'))
            )
            for item in items:
                try:
                    title = item.find_element(By.XPATH, './/div[@class="title"]/a').text
                    price = float(item.find_element(By.CLASS_NAME, "price").text[2:])
                    sales = int(item.find_element(By.CLASS_NAME, "deal-cnt").text[:-3])
                    link = item.find_element(By.XPATH, './/div[@class="title"]/a').get_attribute("href")

                    if price <= max_price and sales >= min_sales:
                        products.append({
                            "title": title,
                            "price": price,
                            "sales": sales,
                            "link": link
                        })
                except:
                    continue

            # 模拟滚动
            self.driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
            time.sleep(random.uniform(2,4))

        except TimeoutException:
            break

    return pd.DataFrame(products)

def send_messages(self, targets, products_df, daily_limit=50):
    sent_count = 0
    for _, product in products_df.iterrows():
        if sent_count >= daily_limit:
            break

        for target in targets:
            try:
                chat_url = f"https://amos.alicdn.com/msg.aw?v=2&uid={target}&site=cntaobao"
                self.driver.get(chat_url)

                # 等待聊天窗口加载
                self.wait.until(
                    EC.presence_of_element_located((By.ID, "J_Textarea"))
                )

                # 构造消息内容
                message = self.message_template.format(
                    product=product["title"],
                    price=product["price"],
                    link=product["link"]
                )

                # 输入并发送消息
                input_box = self.driver.find_element(By.ID, "J_Textarea")
                input_box.clear()
                input_box.send_keys(message)
                time.sleep(random.uniform(1,2))

                send_btn = self.driver.find_element(By.ID, "J_SendBtn")
                send_btn.click()

                sent_count += 1
                print(f"已发送至 {target}: {product['title']}")
                time.sleep(random.uniform(5,10))  # 防封号间隔

            except Exception as e:
                print(f"发送失败: {str(e)}")
                continue

def run(self, config):
    try:
        # 登录阶段
        self.login(config["username"], config["password"])

        # 商品采集阶段
        print("开始采集商品...")
        products = self.search_products(
            keyword=config["keyword"],
            max_price=config["max_price"],
            min_sales=config["min_sales"]
        )
        print(f"采集到 {len(products)} 个符合要求的商品")

        # 消息发送阶段
        print("开始发送消息...")
        self.send_messages(
            targets=config["targets"],
            products_df=products,
            daily_limit=config["daily_limit"]
        )

    finally:
        self.driver.quit()

if name == "main":
config = {
"username": "your_taobao_account",
"password": "your_password",
"keyword": "手机配件",
"max_price": 50,
"min_sales": 100,
"targets": ["target1", "target2", "target3"], # 旺旺ID列表
"daily_limit": 30
}

bot = TaobaoSpammer()
bot.run(config)
相关文章
|
8月前
|
测试技术 Python
Python装饰器:为你的代码施展“魔法”
Python装饰器:为你的代码施展“魔法”
385 100
|
8月前
|
开发者 Python
Python列表推导式:一行代码的艺术与力量
Python列表推导式:一行代码的艺术与力量
575 95
|
8月前
|
缓存 Python
Python装饰器:为你的代码施展“魔法
Python装饰器:为你的代码施展“魔法
483 88
|
8月前
|
监控 机器人 编译器
如何将python代码打包成exe文件---PyInstaller打包之神
PyInstaller可将Python程序打包为独立可执行文件,无需用户安装Python环境。它自动分析代码依赖,整合解释器、库及资源,支持一键生成exe,方便分发。使用pip安装后,通过简单命令即可完成打包,适合各类项目部署。
1431 68
|
9月前
|
数据采集 机器学习/深度学习 人工智能
Python:现代编程的首选语言
Python:现代编程的首选语言
1504 102
|
9月前
|
数据采集 机器学习/深度学习 算法框架/工具
Python:现代编程的瑞士军刀
Python:现代编程的瑞士军刀
488 104
|
9月前
|
人工智能 自然语言处理 算法框架/工具
Python:现代编程的首选语言
Python:现代编程的首选语言
380 103
|
9月前
|
机器学习/深度学习 人工智能 数据挖掘
Python:现代编程的首选语言
Python:现代编程的首选语言
401 82
|
8月前
|
Python
Python编程:运算符详解
本文全面详解Python各类运算符,涵盖算术、比较、逻辑、赋值、位、身份、成员运算符及优先级规则,结合实例代码与运行结果,助你深入掌握Python运算符的使用方法与应用场景。
504 3
|
8月前
|
数据处理 Python
Python编程:类型转换与输入输出
本教程介绍Python中输入输出与类型转换的基础知识,涵盖input()和print()的使用,int()、float()等类型转换方法,并通过综合示例演示数据处理、错误处理及格式化输出,助你掌握核心编程技能。
730 3

推荐镜像

更多