Python淘寶秒殺的腳本實現(xiàn)
準備工作
我們需要把秒殺的商品加入購物車,因為腳本點擊的是全選,所以不需要的商品要移出購物車。
過程分析
1.打開某寶網(wǎng)站;
pq = webdriver.Chrome() pq.get("https://www.taobao.com") # 版權問題 time.sleep(3)
sleep的原因是怕萬一網(wǎng)速慢,網(wǎng)頁加載慢。
2.掃碼登陸;
pq.find_element(By.LINK_TEXT, "親,請登錄").click() print(f"請盡快掃碼登錄") time.sleep(10)
自動點擊進入登錄頁面,我們點擊掃碼登錄進行掃碼。
3.進入購物車;
pq.get("https://cart.taobao.com/cart.htm") time.sleep(3)
登錄成功后,直接進入購物車網(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.結算。
while True: # 獲取電腦現(xiàn)在的時間, year month day now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f') # 對比時間,時間到的話就點擊結算 print(now) if now > lisi: # 點擊結算按鈕 while True: try: if pq.find_element(By.LINK_TEXT, "結 算"): print("here") pq.find_element(By.LINK_TEXT, "結 算").click() print(f"主人,程序鎖定商品,結算成功") 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"主人,結算提交成功,我已幫你搶到商品啦,請及時支付訂單") speaker.Speak(f"主人,結算提交成功,我已幫你搶到商品啦,請及時支付訂單") break time.sleep(0.01)
獲取現(xiàn)在時間與秒殺時間進行比對,時間一到點擊提交訂單生成訂單,生成訂單后支付時間就不需要緊張了。
完整程序實現(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)絡元素 來自 鏈接 文本(親,請登錄) #點擊 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)在的時間, year month day now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f') # 對比時間,時間到的話就點擊結算 print(now) if now > lisi: # 點擊結算按鈕 while True: try: if zhangsan.find_element(By.LINK_TEXT, "結 算"): print("here") zhangsan.find_element(By.LINK_TEXT, "結 算").click() print(f"主人,程序鎖定商品,結算成功") 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"主人,結算提交成功,我已幫你搶到商品啦,請及時支付訂單") speaker.Speak(f"主人,結算提交成功,我已幫你搶到商品啦,請及時支付訂單") break time.sleep(0.01)
到此這篇關于Python淘寶秒殺的腳本實現(xiàn)的文章就介紹到這了,更多相關Python淘寶秒殺內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
打印出python 當前全局變量和入口參數(shù)的所有屬性
打印出python 當前全局變量和入口參數(shù)的所有屬性的實現(xiàn)代碼。2009-07-07Python實戰(zhàn)之利用Geopandas算出每個省面積
GeoPandas是一個基于pandas,針對地理數(shù)據(jù)做了特別支持的第三方模塊。本文將利用GeoPandas計算出每個省的面積,感興趣的小伙伴快跟隨小編一起學習一下吧2021-12-12python實現(xiàn)生命游戲的示例代碼(Game of Life)
這篇文章主要介紹了python實現(xiàn)生命游戲的示例代碼(Game of Life),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-01-01django-crontab實現(xiàn)服務端的定時任務的示例代碼
這篇文章主要介紹了django-crontab實現(xiàn)服務端的定時任務的示例代碼,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-02-02Python3.8如何解決No module named 'numpy&apos
這篇文章主要介紹了Python3.8如何解決No module named 'numpy'報錯問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-06-06pycharm運行程序時出現(xiàn)Run‘python tests for XXX.py‘問題及
這篇文章主要介紹了pycharm運行程序時出現(xiàn)Run ‘python tests for XXX.py‘問題及解決方案,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-08-08