淘宝抢购python代码-仅供学习
需要使用的python工具包有
from selenium import webdriver
import datetime
import time
from selenium.webdriver.common.by import By
本程序调用的是谷歌浏览器,需要下载对应版本的chromedriver.exe,下载网址如下:
下载地址
程序如下:
import os
from selenium import webdriver
import datetime
import time
from selenium.webdriver.common.by import By
from os import path
driver = webdriver.Chrome("C:/Program Files/Google/Chrome/Application/chromedriver")
def login():
driver.get("https://www.taobao.com")
time.sleep(3)
if driver.find_element(By.LINK_TEXT, "亲,请登录"):
driver.find_element(By.LINK_TEXT, value="亲,请登录").click()
print("请在15秒内完成扫码")
time.sleep(15)
driver.get("https://cart.taobao.com/cart.htm")
time.sleep(3)
if driver.find_element(By.ID, "J_SelectAll1"):
driver.find_element(By.ID, "J_SelectAll1").click()
now = datetime.datetime.now()
print("login success:", now.strftime("%Y-%m-%d %H:%M:%S"))
def buy(times):
while True:
now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
print(times)
print(now)
if now == times:
try:
if driver.find_element(By.ID, "J_Go"):
driver.find_element(By.ID, "J_Go").click()
driver.find_element(By.LINK_TEXT, '提交订单').click()
print('抢购成功,请尽快付款')
except:
print('请再次尝试提交订单')
print(now)
time.sleep(0.1)
if __name__ == "__main__":
times = '2022-12-14 10:00:00'
login()
buy(times)