拼多多批量下单软件,拼多多无限账号下单软件,python框架仅供学习参考

简介: 完整的拼多多自动化下单框架,包含登录、搜索商品、获取商品列表、下单等功能。

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

完整的拼多多自动化下单框架,包含登录、搜索商品、获取商品列表、下单等功能。代码使用了Selenium进行网页自动化操作,并加入了随机延迟、多账号支持等功能。请注意这仅用于技术学习。

import time
import random
import requests
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from fake_useragent import UserAgent
from bs4 import BeautifulSoup
import json
import csv
import os
import logging
from multiprocessing import Pool

配置日志

logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
filename='pdd_automation.log'
)
logger = logging.getLogger(name)

class PDDAutomation:
def init(self, headless=True, proxy=None):
self.options = Options()
if headless:
self.options.add_argument('--headless')
if proxy:
self.options.add_argument(f'--proxy-server={proxy}')

    self.options.add_argument('--disable-gpu')
    self.options.add_argument('--no-sandbox')
    self.options.add_argument('--disable-dev-shm-usage')
    self.options.add_argument('--window-size=1920,1080')

    # 随机User-Agent
    ua = UserAgent()
    self.options.add_argument(f'user-agent={ua.random}')

    self.driver = webdriver.Chrome(options=self.options)
    self.wait = WebDriverWait(self.driver, 20)

def login(self, username, password):
    """模拟登录拼多多"""
    try:
        self.driver.get('https://mobile.yangkeduo.com/login.html')

        # 等待登录页面加载
        phone_input = self.wait.until(
            EC.presence_of_element_located((By.XPATH, '//input[@type="tel"]'))
        )

        # 输入用户名和密码
        phone_input.send_keys(username)
        time.sleep(random.uniform(0.5, 1.5))

        # 点击获取验证码
        get_code_btn = self.driver.find_element(By.XPATH, '//button[contains(text(),"获取验证码")]')
        get_code_btn.click()
        time.sleep(random.uniform(2, 3))

        # 这里需要实际处理验证码,示例中跳过
        logger.warning("需要手动处理验证码")
        time.sleep(30)  # 留出时间手动输入验证码

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

        # 等待登录成功
        self.wait.until(
            EC.presence_of_element_located((By.XPATH, '//div[contains(@class,"user-center")]'))
        )

        logger.info(f"登录成功: {username}")
        return True

    except Exception as e:
        logger.error(f"登录失败: {str(e)}")
        return False

def search_product(self, keyword):
    """搜索商品"""
    try:
        search_input = self.wait.until(
            EC.presence_of_element_located((By.XPATH, '//input[@type="search"]'))
        )

        search_input.clear()
        for char in keyword:
            search_input.send_keys(char)
            time.sleep(random.uniform(0.1, 0.3))

        search_input.send_keys(Keys.RETURN)
        time.sleep(random.uniform(2, 3))

        logger.info(f"成功搜索商品: {keyword}")
        return True

    except Exception as e:
        logger.error(f"搜索商品失败: {str(e)}")
        return False

def get_product_list(self, pages=1):
    """获取商品列表"""
    products = []
    try:
        for page in range(pages):
            # 滚动页面加载更多商品
            self.driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
            time.sleep(random.uniform(3, 5))

            # 解析商品列表
            soup = BeautifulSoup(self.driver.page_source, 'html.parser')
            items = soup.find_all('div', class_='goods-item')

            for item in items:
                try:
                    product = {
                        'title': item.find('div', class_='goods-name').get_text(strip=True),
                        'price': item.find('span', class_='price').get_text(strip=True),
                        'sales': item.find('span', class_='sales').get_text(strip=True) if item.find('span', class_='sales') else '0',
                        'link': 'https://mobile.yangkeduo.com' + item.find('a')['href']
                    }
                    products.append(product)
                except Exception as e:
                    logger.warning(f"解析商品失败: {str(e)}")
                    continue

            logger.info(f"已获取第 {page+1} 页商品列表,共 {len(products)} 个商品")

            # 如果有下一页则点击
            next_page = self.driver.find_elements(By.XPATH, '//a[contains(text(),"下一页")]')
            if next_page and page < pages - 1:
                next_page[0].click()
                time.sleep(random.uniform(3, 5))

        return products

    except Exception as e:
        logger.error(f"获取商品列表失败: {str(e)}")
        return products

def place_order(self, product_url, quantity=1):
    """下单商品"""
    try:
        self.driver.get(product_url)
        time.sleep(random.uniform(3, 5))

        # 选择规格
        spec_btn = self.wait.until(
            EC.presence_of_element_located((By.XPATH, '//button[contains(text(),"选择规格")]'))
        )
        spec_btn.click()
        time.sleep(random.uniform(1, 2))

        # 随机选择规格
        specs = self.driver.find_elements(By.XPATH, '//div[contains(@class,"spec-option")]')
        if specs:
            random.choice(specs).click()
            time.sleep(random.uniform(0.5, 1.5))

        # 输入购买数量
        qty_input = self.driver.find_element(By.XPATH, '//input[@type="number"]')
        qty_input.clear()
        qty_input.send_keys(str(quantity))
        time.sleep(random.uniform(0.5, 1.5))

        # 点击确定
        confirm_btn = self.driver.find_element(By.XPATH, '//button[contains(text(),"确定")]')
        confirm_btn.click()
        time.sleep(random.uniform(1, 2))

        # 点击立即购买
        buy_btn = self.wait.until(
            EC.presence_of_element_located((By.XPATH, '//button[contains(text(),"立即购买")]'))
        )
        buy_btn.click()
        time.sleep(random.uniform(2, 3))

        # 提交订单
        submit_btn = self.wait.until(
            EC.presence_of_element_located((By.XPATH, '//button[contains(text(),"提交订单")]'))
        )
        submit_btn.click()
        time.sleep(random.uniform(3, 5))

        logger.info(f"成功下单商品: {product_url}")
        return True

    except Exception as e:
        logger.error(f"下单失败: {str(e)}")
        return False

def batch_order(self, keyword, quantity=1, pages=1, accounts=[]):
    """批量下单"""
    results = []

    # 先搜索商品
    if not self.search_product(keyword):
        return results

    # 获取商品列表
    products = self.get_product_list(pages)
    if not products:
        return results

    # 对每个账号下单
    for account in accounts:
        username, password = account

        # 登录
        if not self.login(username, password):
            continue

        # 对每个商品下单
        for product in random.sample(products, min(3, len(products))):
            result = {
                'account': username,
                'product': product['title'],
                'status': self.place_order(product['link'], quantity)
            }
            results.append(result)

            # 随机间隔
            time.sleep(random.uniform(10, 30))

    return results

def close(self):
    """关闭浏览器"""
    self.driver.quit()
    logger.info("浏览器已关闭")

def load_accounts(filename='accounts.csv'):
"""从CSV加载账号"""
accounts = []
try:
with open(filename, mode='r', encoding='utf-8') as file:
reader = csv.DictReader(file)
for row in reader:
accounts.append((row['username'], row['password']))
except Exception as e:
logger.error(f"加载账号失败: {str(e)}")
return accounts

def save_results(results, filename='results.json'):
"""保存结果到JSON"""
try:
with open(filename, mode='w', encoding='utf-8') as file:
json.dump(results, file, ensure_ascii=False, indent=2)
except Exception as e:
logger.error(f"保存结果失败: {str(e)}")

if name == 'main':

# 示例用法
accounts = load_accounts()
if not accounts:
    accounts = [('13800138000', 'password123')]  # 示例账号

automation = PDDAutomation(headless=False)

try:
    results = automation.batch_order(
        keyword='手机',
        quantity=1,
        pages=2,
        accounts=accounts[:3]  # 测试前3个账号
    )

    save_results(results)
    logger.info(f"批量下单完成,共处理 {len(results)} 个订单")

except Exception as e:
    logger.error(f"主程序出错: {str(e)}")
finally:
    automation.close()
相关文章
|
7天前
|
存储 Java 数据处理
(numpy)Python做数据处理必备框架!(一):认识numpy;从概念层面开始学习ndarray数组:形状、数组转置、数值范围、矩阵...
Numpy是什么? numpy是Python中科学计算的基础包。 它是一个Python库,提供多维数组对象、各种派生对象(例如掩码数组和矩阵)以及用于对数组进行快速操作的各种方法,包括数学、逻辑、形状操作、排序、选择、I/0 、离散傅里叶变换、基本线性代数、基本统计运算、随机模拟等等。 Numpy能做什么? numpy的部分功能如下: ndarray,一个具有矢量算术运算和复杂广播能力的快速且节省空间的多维数组 用于对整组数据进行快速运算的标准数学函数(无需编写循环)。 用于读写磁盘数据的工具以及用于操作内存映射文件的工具。 线性代数、随机数生成以及傅里叶变换功能。 用于集成由C、C++
139 1
|
7天前
|
Java 数据处理 索引
(Pandas)Python做数据处理必选框架之一!(二):附带案例分析;刨析DataFrame结构和其属性;学会访问具体元素;判断元素是否存在;元素求和、求标准值、方差、去重、删除、排序...
DataFrame结构 每一列都属于Series类型,不同列之间数据类型可以不一样,但同一列的值类型必须一致。 DataFrame拥有一个总的 idx记录列,该列记录了每一行的索引 在DataFrame中,若列之间的元素个数不匹配,且使用Series填充时,在DataFrame里空值会显示为NaN;当列之间元素个数不匹配,并且不使用Series填充,会报错。在指定了index 属性显示情况下,会按照index的位置进行排序,默认是 [0,1,2,3,...] 从0索引开始正序排序行。
69 0
|
7天前
|
Java 数据挖掘 数据处理
(Pandas)Python做数据处理必选框架之一!(一):介绍Pandas中的两个数据结构;刨析Series:如何访问数据;数据去重、取众数、总和、标准差、方差、平均值等;判断缺失值、获取索引...
Pandas 是一个开源的数据分析和数据处理库,它是基于 Python 编程语言的。 Pandas 提供了易于使用的数据结构和数据分析工具,特别适用于处理结构化数据,如表格型数据(类似于Excel表格)。 Pandas 是数据科学和分析领域中常用的工具之一,它使得用户能够轻松地从各种数据源中导入数据,并对数据进行高效的操作和分析。 Pandas 主要引入了两种新的数据结构:Series 和 DataFrame。
145 0
|
7天前
|
Java 数据处理 索引
(numpy)Python做数据处理必备框架!(二):ndarray切片的使用与运算;常见的ndarray函数:平方根、正余弦、自然对数、指数、幂等运算;统计函数:方差、均值、极差;比较函数...
ndarray切片 索引从0开始 索引/切片类型 描述/用法 基本索引 通过整数索引直接访问元素。 行/列切片 使用冒号:切片语法选择行或列的子集 连续切片 从起始索引到结束索引按步长切片 使用slice函数 通过slice(start,stop,strp)定义切片规则 布尔索引 通过布尔条件筛选满足条件的元素。支持逻辑运算符 &、|。
61 0
|
7天前
|
存储 JavaScript Java
(Python基础)新时代语言!一起学习Python吧!(四):dict字典和set类型;切片类型、列表生成式;map和reduce迭代器;filter过滤函数、sorted排序函数;lambda函数
dict字典 Python内置了字典:dict的支持,dict全称dictionary,在其他语言中也称为map,使用键-值(key-value)存储,具有极快的查找速度。 我们可以通过声明JS对象一样的方式声明dict
53 1
|
7天前
|
算法 Java Docker
(Python基础)新时代语言!一起学习Python吧!(三):IF条件判断和match匹配;Python中的循环:for...in、while循环;循环操作关键字;Python函数使用方法
IF 条件判断 使用if语句,对条件进行判断 true则执行代码块缩进语句 false则不执行代码块缩进语句,如果有else 或 elif 则进入相应的规则中执行
67 1
|
8月前
|
C语言 Python
Python学习:内建属性、内建函数的教程
本文介绍了Python中的内建属性和内建函数。内建属性包括`__init__`、`__new__`、`__class__`等,通过`dir()`函数可以查看类的所有内建属性。内建函数如`range`、`map`、`filter`、`reduce`和`sorted`等,分别用于生成序列、映射操作、过滤操作、累积计算和排序。其中,`reduce`在Python 3中需从`functools`模块导入。示例代码展示了这些特性和函数的具体用法及注意事项。
111 2
|
存储 算法 API
Python学习五:函数、参数(必选、可选、可变)、变量、lambda表达式、内置函数总结、案例
这篇文章是关于Python函数、参数、变量、lambda表达式、内置函数的详细总结,包含了基础知识点和相关作业练习。
157 0
|
存储 Python Windows
【Python学习篇】Python实验小练习——函数(十)
【Python学习篇】Python实验小练习——函数(十)
98 1
|
存储 Python
【Python学习篇】Python——函数(九)
【Python学习篇】Python——函数(九)
135 1

推荐镜像

更多