Python淘寶秒殺的腳本實(shí)現(xiàn)
準(zhǔn)備工作
我們需要把秒殺的商品加入購物車,因?yàn)槟_本點(diǎn)擊的是全選,所以不需要的商品要移出購物車。
過程分析
1.打開某寶網(wǎng)站;
pq = webdriver.Chrome()
pq.get("https://www.taobao.com") # 版權(quán)問題
time.sleep(3)
sleep的原因是怕萬一網(wǎng)速慢,網(wǎng)頁加載慢。
2.掃碼登陸;
pq.find_element(By.LINK_TEXT, "親,請(qǐng)登錄").click() print(f"請(qǐng)盡快掃碼登錄") time.sleep(10)
自動(dòng)點(diǎn)擊進(jìn)入登錄頁面,我們點(diǎn)擊掃碼登錄進(jìn)行掃碼。
3.進(jìn)入購物車;
pq.get("https://cart.taobao.com/cart.htm")
time.sleep(3)
登錄成功后,直接進(jìn)入購物車網(wǎng)站。
4.全選購物車;
while True:
try: # 查找 元素 來自 ID
if pq.find_element(By.ID, "J_SelectAll1"):
pq.find_element(By.ID, "J_SelectAll1").click()
break
except:
print(f"找不到購買按鈕")
找到全選按鈕,全選。

5.結(jié)算。
while True:
# 獲取電腦現(xiàn)在的時(shí)間, year month day
now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')
# 對(duì)比時(shí)間,時(shí)間到的話就點(diǎn)擊結(jié)算
print(now)
if now > lisi:
# 點(diǎn)擊結(jié)算按鈕
while True:
try:
if pq.find_element(By.LINK_TEXT, "結(jié) 算"):
print("here")
pq.find_element(By.LINK_TEXT, "結(jié) 算").click()
print(f"主人,程序鎖定商品,結(jié)算成功")
break
except:
pass
while True:
try:
if pq.find_element_by_link_text('提交訂單'):
pq.find_element_by_link_text('提交訂單').click()
print(f"搶購成功,請(qǐng)盡快付款")
except:
print(f"主人,結(jié)算提交成功,我已幫你搶到商品啦,請(qǐng)及時(shí)支付訂單")
speaker.Speak(f"主人,結(jié)算提交成功,我已幫你搶到商品啦,請(qǐng)及時(shí)支付訂單")
break
time.sleep(0.01)

獲取現(xiàn)在時(shí)間與秒殺時(shí)間進(jìn)行比對(duì),時(shí)間一到點(diǎn)擊提交訂單生成訂單,生成訂單后支付時(shí)間就不需要緊張了。

完整程序?qū)崿F(xiàn)如下:
import datetime
import win32com.client
import time
from selenium.webdriver.common.by import By
from selenium import webdriver
now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')
speaker = win32com.client.Dispatch("SAPI.SpVoice")
lisi = "2022-11-11 20:00:00.00000000"
zhangsan = webdriver.Chrome()
zhangsan.get("https://www.taobao.com")
time.sleep(3) # 查找 網(wǎng)絡(luò)元素 來自 鏈接 文本(親,請(qǐng)登錄) #點(diǎn)擊
zhangsan.find_element(By.LINK_TEXT, "親,請(qǐng)登錄").click()
print(f"請(qǐng)盡快掃碼登錄")
time.sleep(10)
zhangsan.get("https://cart.taobao.com/cart.htm")
time.sleep(3)
# 是否全選購物車
while True:
try: # 查找 元素 來自 ID
if zhangsan.find_element(By.ID, "J_SelectAll1"):
zhangsan.find_element(By.ID, "J_SelectAll1").click()
break
except:
print(f"找不到購買按鈕")
while True:
# 獲取電腦現(xiàn)在的時(shí)間, year month day
now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')
# 對(duì)比時(shí)間,時(shí)間到的話就點(diǎn)擊結(jié)算
print(now)
if now > lisi:
# 點(diǎn)擊結(jié)算按鈕
while True:
try:
if zhangsan.find_element(By.LINK_TEXT, "結(jié) 算"):
print("here")
zhangsan.find_element(By.LINK_TEXT, "結(jié) 算").click()
print(f"主人,程序鎖定商品,結(jié)算成功")
break
except:
pass
while True:
try:
if zhangsan.find_element_by_link_text('提交訂單'):
zhangsan.find_element_by_link_text('提交訂單').click()
print(f"搶購成功,請(qǐng)盡快付款")
except:
print(f"主人,結(jié)算提交成功,我已幫你搶到商品啦,請(qǐng)及時(shí)支付訂單")
speaker.Speak(f"主人,結(jié)算提交成功,我已幫你搶到商品啦,請(qǐng)及時(shí)支付訂單")
break
time.sleep(0.01)
到此這篇關(guān)于Python淘寶秒殺的腳本實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)Python淘寶秒殺內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
python3通過subprocess模塊調(diào)用腳本并和腳本交互的操作
這篇文章主要介紹了python3通過subprocess模塊調(diào)用腳本并和腳本交互的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-12-12
Python OpenCV實(shí)現(xiàn)圖片上輸出中文
這篇文章主要為大家詳細(xì)介紹了Python OpenCV實(shí)現(xiàn)圖片上輸出中文,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-01-01
TensorFlow實(shí)現(xiàn)數(shù)據(jù)增強(qiáng)的示例代碼
?TensorFlow數(shù)據(jù)增強(qiáng)?是一種通過變換和擴(kuò)充訓(xùn)練數(shù)據(jù)的方法,本文主要介紹了TensorFlow實(shí)現(xiàn)數(shù)據(jù)增強(qiáng)的示例代碼,具有一定的參考價(jià)值,感興趣的可以了解游戲2024-08-08
使用Python3實(shí)現(xiàn)判斷函數(shù)的圈復(fù)雜度
編寫函數(shù)最重要的原則就是:別寫太復(fù)雜的函數(shù),那什么樣的函數(shù)才能算是過于復(fù)雜?一般會(huì)通過兩個(gè)標(biāo)準(zhǔn)來判斷,長度和圈復(fù)雜度,下面我們就來看看如何使用Python判斷函數(shù)的圈復(fù)雜度吧2024-04-04

