使用Python实现淘宝订单定时付款

来源:互联网 发布:seo名录 编辑:程序博客网 时间:2024/04/28 15:56

今天教大家如何使用Python+Selenium实现淘宝订单定时付款,用处想必大家都知道。

一、环境安装

1.python 3.6 安装

Python3.6下载链接 https://www.liaoxuefeng.com/files/attachments/0014222393965540081463bf8a9499094bdda24b6fdf2d6000
enter image description here
特别要注意选上pip和Add python.exe to Path,然后一路点“Next”即可完成安装。
若前面忘记勾选Add python.exe to Path该选项,则需要手动添加Path环境变量。

2.检查Python是否安装成功

打开cmd输入python,若返回结果如图所示则表示安装成功
这里写图片描述

3.Selenium for Python

在命令行中输入pip install selenium 即系统会自动帮您下载安装。
这里写图片描述


二、程序编辑(此处只对Chrome浏览器有效)

1.安装ChromeDriver

选择自己合适的ChromeDriver下载,将其放在Chrome目录下,并添加ChromeDriver的环境变量。
http://chromedriver.storage.googleapis.com/index.html?path=2.9/

2.获取Chrome的User Data所在路径

记录下个人资料路径,将之后的\Default去除 如C:\Users\11304\AppData\Local\Google\Chrome\User Data,之后会用到
这里写图片描述

3.编辑程序

新建一个.py文件,将如下程序复制到该文件下。

注:UserData 、所有订单网页链接、淘宝登录密码、淘宝支付密码都改为自己的
from selenium import webdriverfrom selenium.webdriver.common.action_chains import ActionChainsimport timeUserData = 'Chrome用户数据存放路径'所有订单网页链接 = '此处替换您的链接'淘宝登录密码 = '淘宝登录密码'淘宝支付密码 = '淘宝支付密码'if __name__ == '__main__':    option = webdriver.ChromeOptions()    option.add_argument(UserData)    driver = webdriver.Chrome(chrome_options=option)    driver.get(所有订单网页链接)    pswInput = driver.find_element_by_name('TPL_password')    pswInput.send_keys(淘宝登录密码)    loginBtn = driver.find_element_by_id('J_SubmitStatic')    loginBtn.click()    time.sleep(2)    select = driver.find_element_by_xpath('//*[@id="tp-bought-root"]/div[3]/div[1]/label')    select.click()    time.sleep(0.2)    btn = driver.find_element_by_xpath('//*[@id="tp-bought-root"]/div[3]/div[1]/div/button[1]')    btn.click()    driver.switch_to_window(driver.window_handles[1])    time.sleep(0.5)    pswInput = driver.find_element_by_id('payPassword_rsainput')    pswInput.send_keys(淘宝支付密码)    J_authSubmit = driver.find_element_by_id('J_authSubmit')    while (not_executed):        dt = list(time.localtime())        hour = dt[3]        minute = dt[4]        if hour == 0 and minute == 0:            not_executed = 0    J_authSubmit.click()

4.执行程序

在此打开CMD输入“’python ‘上段程序所在路径’ ”,即可运行该段程序,就可以定时付款您想要的商品了

阅读全文
3 0
原创粉丝点击