阿里旺旺私信群发工具,淘宝商家私信群发软件,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)
相关文章
|
5天前
|
Python
Python的简洁之道:5个让代码更优雅的技巧
Python的简洁之道:5个让代码更优雅的技巧
147 104
|
5天前
|
开发者 Python
Python神技:用列表推导式让你的代码更优雅
Python神技:用列表推导式让你的代码更优雅
191 99
|
5天前
|
设计模式 人工智能 API
AI智能体开发实战:17种核心架构模式详解与Python代码实现
本文系统解析17种智能体架构设计模式,涵盖多智能体协作、思维树、反思优化与工具调用等核心范式,结合LangChain与LangGraph实现代码工作流,并通过真实案例验证效果,助力构建高效AI系统。
82 7
|
7天前
|
JSON 缓存 开发者
淘宝商品详情接口(item_get)企业级全解析:参数配置、签名机制与 Python 代码实战
本文详解淘宝开放平台taobao.item_get接口对接全流程,涵盖参数配置、MD5签名生成、Python企业级代码实现及高频问题排查,提供可落地的实战方案,助你高效稳定获取商品数据。
|
算法 编译器 开发者
如何提高Python代码的性能:优化技巧与实践
本文探讨了如何提高Python代码的性能,重点介绍了一些优化技巧与实践方法。通过使用适当的数据结构、算法和编程范式,以及利用Python内置的性能优化工具,可以有效地提升Python程序的执行效率,从而提升整体应用性能。本文将针对不同场景和需求,分享一些实用的优化技巧,并通过示例代码和性能测试结果加以说明。
|
人工智能 数据挖掘 数据处理
揭秘Python编程之美:从基础到进阶的代码实践之旅
【9月更文挑战第14天】本文将带领读者深入探索Python编程语言的魅力所在。通过简明扼要的示例,我们将揭示Python如何简化复杂问题,提升编程效率。无论你是初学者还是有一定经验的开发者,这篇文章都将为你打开一扇通往高效编码世界的大门。让我们开始这段充满智慧和乐趣的Python编程之旅吧!
|
11月前
|
机器学习/深度学习 数据采集 人工智能
探索机器学习:从理论到Python代码实践
【10月更文挑战第36天】本文将深入浅出地介绍机器学习的基本概念、主要算法及其在Python中的实现。我们将通过实际案例,展示如何使用scikit-learn库进行数据预处理、模型选择和参数调优。无论你是初学者还是有一定基础的开发者,都能从中获得启发和实践指导。
156 2
|
12月前
|
大数据 Python
Python 高级编程:深入探索高级代码实践
本文深入探讨了Python的四大高级特性:装饰器、生成器、上下文管理器及并发与并行编程。通过装饰器,我们能够在不改动原函数的基础上增添功能;生成器允许按需生成值,优化处理大数据;上下文管理器确保资源被妥善管理和释放;多线程等技术则助力高效完成并发任务。本文通过具体代码实例详细解析这些特性的应用方法,帮助读者提升Python编程水平。
514 5
|
机器学习/深度学习 Python
时间序列特征提取:从理论到Python代码实践
时间序列是一种特殊的存在。这意味着你对表格数据或图像进行的许多转换/操作/处理技术对于时间序列来说可能根本不起作用。
324 1
时间序列特征提取:从理论到Python代码实践
|
数据采集 数据可视化 数据挖掘
使用Python进行数据分析的新手指南深入浅出操作系统:从理论到代码实践
【8月更文挑战第30天】在数据驱动的世界中,掌握数据分析技能变得越来越重要。本文将引导你通过Python这门强大的编程语言来探索数据分析的世界。我们将从安装必要的软件包开始,逐步学习如何导入和清洗数据,以及如何使用Pandas库进行数据操作。文章最后会介绍如何使用Matplotlib和Seaborn库来绘制数据图表,帮助你以视觉方式理解数据。无论你是编程新手还是有经验的开发者,这篇文章都将为你打开数据分析的大门。

推荐镜像

更多