淘宝商家私信群发脚本,阿里旺旺私信群发工具,卖家私信批量发送插件【python框架】

简介: 使用Selenium自动化登录淘宝账号通过阿里旺旺网页版发送私信

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

这个淘宝私信群发工具主要包含以下功能:

使用Selenium自动化登录淘宝账号
通过阿里旺旺网页版发送私信
支持从CSV文件批量读取客户信息
支持消息模板,可自定义变量
添加随机延迟防止被封号
完整的错误处理和日志记录
使用前需要安装依赖:pip install selenium pandas

源码部分:【仅供学习参考】

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

class TaobaoMassMessenger:
def init(self, username, password):
self.username = username
self.password = password
self.driver = None
self.wait_time = 10
self.message_delay = (3, 7) # 随机延迟范围(秒)

def init_driver(self):
    options = webdriver.ChromeOptions()
    options.add_argument("--disable-notifications")
    options.add_argument("--disable-infobars")
    options.add_argument("--start-maximized")
    self.driver = webdriver.Chrome(options=options)
    self.driver.implicitly_wait(self.wait_time)

def login(self):
    self.driver.get("https://login.taobao.com/")

    # 切换到密码登录
    try:
        password_login = WebDriverWait(self.driver, self.wait_time).until(
            EC.presence_of_element_located((By.XPATH, "//a[contains(text(),'密码登录')]"))
        )
        password_login.click()
    except Exception as e:
        print("无法找到密码登录选项:", e)
        return False

    # 输入用户名和密码
    try:
        username_input = WebDriverWait(self.driver, self.wait_time).until(
            EC.presence_of_element_located((By.ID, "fm-login-id"))
        )
        password_input = self.driver.find_element(By.ID, "fm-login-password")

        username_input.clear()
        username_input.send_keys(self.username)
        time.sleep(1)

        password_input.clear()
        password_input.send_keys(self.password)
        time.sleep(1)

        # 点击登录按钮
        login_button = self.driver.find_element(By.XPATH, "//button[contains(text(),'登 录')]")
        login_button.click()

        # 等待登录成功
        WebDriverWait(self.driver, 30).until(
            EC.presence_of_element_located((By.ID, "q"))
        )
        return True
    except Exception as e:
        print("登录失败:", e)
        return False

def send_message_to_user(self, username, message):
    try:
        # 打开旺旺聊天窗口
        self.driver.get(f"https://amos.alicdn.com/msg.aw?v=2&uid={username}&site=cntaobao&s=1&charset=utf-8")

        # 等待聊天窗口加载完成
        WebDriverWait(self.driver, self.wait_time).until(
            EC.presence_of_element_located((By.ID, "J_Textarea"))
        )

        # 输入消息
        textarea = self.driver.find_element(By.ID, "J_Textarea")
        textarea.clear()
        for line in message.split('\n'):
            textarea.send_keys(line)
            textarea.send_keys(Keys.SHIFT, Keys.ENTER)
        time.sleep(1)

        # 发送消息
        send_button = self.driver.find_element(By.ID, "J_SendBtn")
        send_button.click()

        # 随机延迟
        time.sleep(random.uniform(*self.message_delay))
        return True
    except Exception as e:
        print(f"发送消息给 {username} 失败:", e)
        return False

def send_messages_from_csv(self, csv_file, message_template):
    try:
        df = pd.read_csv(csv_file)
        success_count = 0
        fail_count = 0

        for index, row in df.iterrows():
            username = row['username']
            custom_message = message_template.format(**row.to_dict())

            print(f"正在发送消息给 {username}...")
            if self.send_message_to_user(username, custom_message):
                success_count += 1
                print(f"成功发送消息给 {username}")
            else:
                fail_count += 1
                print(f"发送消息给 {username} 失败")

            # 随机延迟防止被封
            time.sleep(random.uniform(5, 15))

        print(f"\n发送完成: 成功 {success_count} 条, 失败 {fail_count} 条")
        return True
    except Exception as e:
        print("发送消息过程中出错:", e)
        return False

def close(self):
    if self.driver:
        self.driver.quit()

if name == "main":

# 配置信息
USERNAME = "your_taobao_username"
PASSWORD = "your_taobao_password"
CSV_FILE = "customers.csv"  # 包含username列和其他自定义列的CSV文件
MESSAGE_TEMPLATE = """亲爱的{username}:

感谢您对我们店铺的支持!我们最近推出了新品{product_name},原价{original_price}元,现在特价仅需{discount_price}元!

点击链接查看详情:{product_link}

有任何问题欢迎随时咨询哦~"""

# 创建并运行发送器
messenger = TaobaoMassMessenger(USERNAME, PASSWORD)
try:
    messenger.init_driver()
    if messenger.login():
        messenger.send_messages_from_csv(CSV_FILE, MESSAGE_TEMPLATE)
except Exception as e:
    print("程序运行出错:", e)
finally:
    messenger.close()

username,product_name,original_price,discount_price,product_link
customer1,新款T恤,199,159,https://item.taobao.com/item1
customer2,休闲裤,299,239,https://item.taobao.com/item2
customer3,运动鞋,599,499,https://item.taobao.com/item3

相关文章
|
5月前
|
存储 缓存 测试技术
理解Python装饰器:简化代码的强大工具
理解Python装饰器:简化代码的强大工具
|
6月前
|
程序员 测试技术 开发者
Python装饰器:简化代码的强大工具
Python装饰器:简化代码的强大工具
251 92
|
5月前
|
机器学习/深度学习 编解码 Python
Python图片上采样工具 - RealESRGANer
Real-ESRGAN基于深度学习实现图像超分辨率放大,有效改善传统PIL缩放的模糊问题。支持多种模型版本,推荐使用魔搭社区提供的预训练模型,适用于将小图高质量放大至大图,放大倍率越低效果越佳。
412 3
|
5月前
|
算法 安全 数据安全/隐私保护
Python随机数函数全解析:5个核心工具的实战指南
Python的random模块不仅包含基础的随机数生成函数,还提供了如randint()、choice()、shuffle()和sample()等实用工具,适用于游戏开发、密码学、统计模拟等多个领域。本文深入解析这些函数的用法、底层原理及最佳实践,帮助开发者高效利用随机数,提升代码质量与安全性。
983 0
|
5月前
|
数据采集 机器学习/深度学习 人工智能
Python:现代编程的首选语言
Python:现代编程的首选语言
447 102
|
5月前
|
数据采集 机器学习/深度学习 算法框架/工具
Python:现代编程的瑞士军刀
Python:现代编程的瑞士军刀
393 104

推荐镜像

更多