淘宝批量发货发布工具, 淘宝批量上传商品软件, 淘宝批量上架软件【python】

简介: 使用Selenium实现自动化操作淘宝卖家后台支持三种核心功能

文章附件下载:https://www.pan38.com/dow/share.php?code=JCnzE 提取密码:2778

代码功能说明:
使用Selenium实现自动化操作淘宝卖家后台
支持三种核心功能:批量上传商品、批量上架商品和批量发货
商品信息通过Excel文件导入,支持多商品批量处理
包含完善的异常处理和等待机制,确保操作稳定性
采用面向对象设计,代码结构清晰易于扩展
模拟真实用户操作流程,避免被平台检测为机器人

import os
import time
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 TaobaoBatchTool:
def init(self, username, password):
self.username = username
self.password = password
self.driver = None
self.wait_time = 10
self.init_driver()

def init_driver(self):
    """初始化浏览器驱动"""
    options = webdriver.ChromeOptions()
    options.add_argument('--disable-blink-features=AutomationControlled')
    options.add_argument('--start-maximized')
    self.driver = webdriver.Chrome(options=options)
    self.driver.implicitly_wait(self.wait_time)

def login(self):
    """登录淘宝卖家中心"""
    try:
        self.driver.get('https://login.taobao.com/')
        WebDriverWait(self.driver, self.wait_time).until(
            EC.presence_of_element_located((By.ID, 'fm-login-id'))
        ).send_keys(self.username)

        self.driver.find_element(By.ID, 'fm-login-password').send_keys(self.password)
        self.driver.find_element(By.CSS_SELECTOR, '.fm-button.fm-submit.password-login').click()

        # 等待登录成功
        WebDriverWait(self.driver, self.wait_time).until(
            EC.presence_of_element_located((By.LINK_TEXT, '卖家中心'))
        )
        print("登录成功")
        return True
    except Exception as e:
        print(f"登录失败: {str(e)}")
        return False

def batch_upload_products(self, product_file):
    """批量上传商品"""
    try:
        products = pd.read_excel(product_file)
        self.driver.get('https://sell.taobao.com/auction/merchandise/auction_list.htm')

        for index, row in products.iterrows():
            try:
                # 点击发布商品按钮
                WebDriverWait(self.driver, self.wait_time).until(
                    EC.element_to_be_clickable((By.LINK_TEXT, '发布商品'))
                ).click()

                # 选择商品类目
                WebDriverWait(self.driver, self.wait_time).until(
                    EC.presence_of_element_located((By.ID, 'J_Category'))
                ).click()

                # 填写商品信息
                self._fill_product_info(row)

                # 提交商品
                self.driver.find_element(By.ID, 'J_Submit').click()
                print(f"成功上传商品: {row['title']}")
                time.sleep(2)  # 防止操作过快

            except Exception as e:
                print(f"上传商品 {row['title']} 失败: {str(e)}")
                continue

        return True
    except Exception as e:
        print(f"批量上传商品失败: {str(e)}")
        return False

def _fill_product_info(self, product):
    """填写商品详细信息"""
    # 商品标题
    self.driver.find_element(By.ID, 'J_Title').send_keys(product['title'])

    # 商品价格
    self.driver.find_element(By.ID, 'J_Price').send_keys(str(product['price']))

    # 商品库存
    self.driver.find_element(By.ID, 'J_Quantity').send_keys(str(product['quantity']))

    # 商品描述
    self.driver.switch_to.frame('J_DescIframe')
    self.driver.find_element(By.TAG_NAME, 'body').send_keys(product['description'])
    self.driver.switch_to.default_content()

    # 上传主图
    for img in product['images'].split(','):
        self.driver.find_element(By.CSS_SELECTOR, '.uploader-pick').send_keys(os.path.abspath(img.strip()))
        time.sleep(1)

def batch_list_products(self, product_ids):
    """批量上架商品"""
    try:
        self.driver.get('https://sell.taobao.com/auction/merchandise/auction_list.htm')

        for product_id in product_ids:
            try:
                # 搜索商品
                search_box = WebDriverWait(self.driver, self.wait_time).until(
                    EC.presence_of_element_located((By.ID, 'search-key'))
                )
                search_box.clear()
                search_box.send_keys(product_id)
                search_box.send_keys(Keys.RETURN)

                # 勾选商品
                WebDriverWait(self.driver, self.wait_time).until(
                    EC.presence_of_element_located((By.CSS_SELECTOR, f'input[value="{product_id}"]'))
                ).click()

                # 点击上架按钮
                self.driver.find_element(By.LINK_TEXT, '上架').click()
                print(f"成功上架商品ID: {product_id}")
                time.sleep(1)

            except Exception as e:
                print(f"上架商品ID {product_id} 失败: {str(e)}")
                continue

        return True
    except Exception as e:
        print(f"批量上架商品失败: {str(e)}")
        return False

def batch_ship_orders(self, order_file):
    """批量发货"""
    try:
        orders = pd.read_excel(order_file)
        self.driver.get('https://trade.taobao.com/trade/itemlist/list_sold_items.htm')

        for index, row in orders.iterrows():
            try:
                # 搜索订单
                search_box = WebDriverWait(self.driver, self.wait_time).until(
                    EC.presence_of_element_located((By.ID, 'search-order-input'))
                )
                search_box.clear()
                search_box.send_keys(row['order_id'])
                search_box.send_keys(Keys.RETURN)

                # 勾选订单
                WebDriverWait(self.driver, self.wait_time).until(
                    EC.presence_of_element_located((By.CSS_SELECTOR, f'input[value="{row["order_id"]}"]'))
                ).click()

                # 点击发货按钮
                self.driver.find_element(By.LINK_TEXT, '发货').click()

                # 填写物流信息
                self._fill_shipping_info(row)

                # 确认发货
                self.driver.find_element(By.ID, 'J_Confirm').click()
                print(f"成功发货订单: {row['order_id']}")
                time.sleep(1)

            except Exception as e:
                print(f"发货订单 {row['order_id']} 失败: {str(e)}")
                continue

        return True
    except Exception as e:
        print(f"批量发货失败: {str(e)}")
        return False

def _fill_shipping_info(self, order):
    """填写物流信息"""
    # 选择物流公司
    self.driver.find_element(By.CSS_SELECTOR, '.logistics-company').click()
    self.driver.find_element(By.XPATH, f"//li[contains(text(), '{order['shipping_company']}')]").click()

    # 填写运单号
    self.driver.find_element(By.ID, 'J_LogisticCode').send_keys(order['tracking_number'])

def close(self):
    """关闭浏览器"""
    if self.driver:
        self.driver.quit()

def main():

# 示例用法
tool = TaobaoBatchTool('your_username', 'your_password')

try:
    if tool.login():
        # 批量上传商品
        tool.batch_upload_products('products.xlsx')

        # 批量上架商品
        product_ids = ['123456', '789012']
        tool.batch_list_products(product_ids)

        # 批量发货
        tool.batch_ship_orders('orders.xlsx')

finally:
    tool.close()

if name == 'main':
main()

相关文章
|
5月前
|
JSON 算法 API
Python采集淘宝商品评论API接口及JSON数据返回全程指南
Python采集淘宝商品评论API接口及JSON数据返回全程指南
|
5月前
|
JSON API 数据安全/隐私保护
Python采集淘宝拍立淘按图搜索API接口及JSON数据返回全流程指南
通过以上流程,可实现淘宝拍立淘按图搜索的完整调用链路,并获取结构化的JSON商品数据,支撑电商比价、智能推荐等业务场景。
|
6月前
|
缓存 监控 算法
唯品会item_search - 按关键字搜索 VIP 商品接口深度分析及 Python 实现
唯品会item_search接口支持通过关键词、分类、价格等条件检索商品,广泛应用于电商数据分析、竞品监控与市场调研。结合Python可实现搜索、分析、可视化及数据导出,助力精准决策。
|
6月前
|
JSON 缓存 供应链
电子元件 item_search - 按关键字搜索商品接口深度分析及 Python 实现
本文深入解析电子元件item_search接口的设计逻辑与Python实现,涵盖参数化筛选、技术指标匹配、供应链属性过滤及替代型号推荐等核心功能,助力高效精准的电子元器件搜索与采购决策。
|
6月前
|
缓存 供应链 芯片
电子元件类商品 item_get - 商品详情接口深度分析及 Python 实现
电子元件商品接口需精准返回型号参数、规格属性、认证及库存等专业数据,支持供应链管理与采购决策。本文详解其接口特性、数据结构与Python实现方案。
|
6月前
|
JSON 缓存 开发者
淘宝商品详情接口(item_get)企业级全解析:参数配置、签名机制与 Python 代码实战
本文详解淘宝开放平台taobao.item_get接口对接全流程,涵盖参数配置、MD5签名生成、Python企业级代码实现及高频问题排查,提供可落地的实战方案,助你高效稳定获取商品数据。
|
6月前
|
缓存 算法 数据安全/隐私保护
VVICitem_search - 根据关键词取关键词取商品列表接口深度分析及 Python 实现
VVIC item_search接口支持关键词搜索服装商品,提供价格、销量、供应商等数据,助力市场调研与采购决策。
|
6月前
|
缓存 自然语言处理 算法
item_search - Lazada 按关键字搜索商品接口深度分析及 Python 实现
Lazada的item_search接口是关键词搜索商品的核心工具,支持多语言、多站点,可获取商品价格、销量、评分等数据,适用于市场调研与竞品分析。

推荐镜像

更多