淘宝自动下单
程序员文章站
2024-01-22 12:24:04
from selenium import webdriverfrom time import sleepimport datetimeimport timeoption = webdriver.ChromeOptions()option.add_argument('disable-infobars')#打开淘宝网站def login(): driver.get('https://www.taobao.com') time.sleep(2) #登录淘宝账户且......
环境
1. win10
2.python3.8
3.Google Chrome 浏览器
用的浏览器版本,打开浏览器 右上角3个点号-->帮助-->关于查看版本号,然后在此网站下载对应版本号
http://npm.taobao.org/mirrors/chromedriver
下面是具体的脚本,如果有问题可以私信我,
from selenium import webdriver
from time import sleep
import datetime
import time
option = webdriver.ChromeOptions()
option.add_argument('disable-infobars')
#打开淘宝网站
def login():
driver.get('https://www.taobao.com')
time.sleep(2)
#登录淘宝账户且扫码登录
driver.find_element_by_link_text("亲,请登录").click()
driver.find_element_by_class_name("icon-qrcode").click()
time.sleep(10)
#打开购物车
driver.get('https://cart.taobao.com/cart.htm')
time.sleep(5)
#全选
driver.find_element_by_id('J_SelectAll2').click()
# print('全选时间:' + now)
def buy(times):
while True:
now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')
if now > times:
try:
if driver.find_element_by_link_text("结 算"):
driver.find_element_by_link_text("结 算").click()
print("成功")
break
except:
pass
continue
else:
print('时间未到,现在时间是:' + now)
time.sleep(0.01)
continue
while True:
try:
if driver.find_element_by_xpath('//*[@id="submitOrderPC_1"]/div[1]/a[2]'):
driver.find_element_by_xpath('//*[@id="submitOrderPC_1"]/div[1]/a[2]').click()
print("提交成功")
break
except:
print('找不到提交订单')
time.sleep(0.01)
continue
if __name__=='__main__':
now_login = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')
times = input("格式为:" + now_login + ",请输入抢购时间:")
# download the driver from http://npm.taobao.org/mirrors/chromedriver
driver = webdriver.Chrome(r'D:\Coding\taobao123\chromedriver.exe')
login()
buy(times)
本文地址:https://blog.csdn.net/zuopiezia/article/details/109612014