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, "親,請登錄").click() print(f"請盡快掃碼登錄") 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')
# 對比時(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"搶購成功,請盡快付款")
except:
print(f"主人,結(jié)算提交成功,我已幫你搶到商品啦,請及時(shí)支付訂單")
speaker.Speak(f"主人,結(jié)算提交成功,我已幫你搶到商品啦,請及時(shí)支付訂單")
break
time.sleep(0.01)

獲取現(xiàn)在時(shí)間與秒殺時(shí)間進(jìn)行比對,時(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ò)元素 來自 鏈接 文本(親,請登錄) #點(diǎn)擊
zhangsan.find_element(By.LINK_TEXT, "親,請登錄").click()
print(f"請盡快掃碼登錄")
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')
# 對比時(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"搶購成功,請盡快付款")
except:
print(f"主人,結(jié)算提交成功,我已幫你搶到商品啦,請及時(shí)支付訂單")
speaker.Speak(f"主人,結(jié)算提交成功,我已幫你搶到商品啦,請及時(shí)支付訂單")
break
time.sleep(0.01)
到此這篇關(guān)于Python淘寶秒殺的腳本實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)Python淘寶秒殺內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
如何使用pandas對超大csv文件進(jìn)行快速拆分詳解
Pandas是Python語言的一個(gè)擴(kuò)展程序庫,提供高性能、易于使用的數(shù)據(jù)結(jié)構(gòu)和數(shù)據(jù)分析工具,下面這篇文章主要給大家介紹了關(guān)于如何使用pandas對超大csv文件進(jìn)行快速拆分的相關(guān)資料,需要的朋友可以參考下2022-07-07
打印出python 當(dāng)前全局變量和入口參數(shù)的所有屬性
打印出python 當(dāng)前全局變量和入口參數(shù)的所有屬性的實(shí)現(xiàn)代碼。2009-07-07
Python實(shí)戰(zhàn)之利用Geopandas算出每個(gè)省面積
GeoPandas是一個(gè)基于pandas,針對地理數(shù)據(jù)做了特別支持的第三方模塊。本文將利用GeoPandas計(jì)算出每個(gè)省的面積,感興趣的小伙伴快跟隨小編一起學(xué)習(xí)一下吧2021-12-12
python實(shí)現(xiàn)生命游戲的示例代碼(Game of Life)
這篇文章主要介紹了python實(shí)現(xiàn)生命游戲的示例代碼(Game of Life),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-01-01
使用Python三角函數(shù)公式計(jì)算三角形的夾角案例
這篇文章主要介紹了使用Python三角函數(shù)公式計(jì)算三角形的夾角案例,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-04-04
django-crontab實(shí)現(xiàn)服務(wù)端的定時(shí)任務(wù)的示例代碼
這篇文章主要介紹了django-crontab實(shí)現(xiàn)服務(wù)端的定時(shí)任務(wù)的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-02-02
Python3.8如何解決No module named 'numpy&apos
這篇文章主要介紹了Python3.8如何解決No module named 'numpy'報(bào)錯(cuò)問題,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-06-06
pycharm運(yùn)行程序時(shí)出現(xiàn)Run‘python tests for XXX.py‘問題及
這篇文章主要介紹了pycharm運(yùn)行程序時(shí)出現(xiàn)Run ‘python tests for XXX.py‘問題及解決方案,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-08-08

