我這里使用的chorme瀏覽器,使用前購物車內需要有商品
一、ChromeDriver的安裝
若想使用Selenium成功調用Chrome瀏覽器完成相應的操作,需要通過ChromeDriver來驅動。
這里是ChromeDriver的官方下載地址。
鏈接:https://chromedriver.storage.googleapis.com/index.html
我們在下載之前先來確認下我們使用的Chrome瀏覽器版本,只需要紅框內幾位相同即可


根據自己操作系統選擇

Python安裝路徑下Scripts文件夾中即可

二、實現代碼
from selenium import webdriver
import time
import datetime
# 打開Chrome瀏覽器
browser = webdriver.Chrome()
def login():
# 打開淘寶首頁,通過掃碼登錄
browser.get("https://www.taobao.com")
time.sleep(3)
if browser.find_element_by_link_text("親,請登錄"):
browser.find_element_by_link_text("親,請登錄").click()
print(f"請盡快掃碼登錄")
time.sleep(10)
def picking(method):
# 打開購物車列表頁面
browser.get("https://cart.taobao.com/cart.htm")
time.sleep(3)
# 是否全選購物車
if method == 0:
while True:
try:
if browser.find_element_by_id("J_SelectAll1"):
browser.find_element_by_id("J_SelectAll1").click()
break
except:
print(f"找不到購買按鈕")
else:
print(f"請手動勾選需要購買的商品")
time.sleep(5)
def buy(times):
while True:
now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')
print(now)
# 對比時間,時間到的話就點擊結算
if now > times:
# 點擊結算按鈕
while True:
try:
if browser.find_element_by_id("J_Go"):
browser.find_element_by_id("J_Go").click()
print(f"結算成功,準備提交訂單")
break
except:
pass
# 點擊提交訂單按鈕
while True:
try:
if browser.find_element_by_link_text('提交訂單'):
browser.find_element_by_link_text('提交訂單').click()
print(f"搶購成功,請盡快付款")
except:
print(f"再次嘗試提交訂單")
time.sleep(0.01)
if __name__ == '__main__':
login();
picking(0);
buy("2021-05-12 21:57:08.211142"); #修改為自己所需要的時間,注意時間格式一定要對
到此這篇關于python淘寶準點秒殺搶單的實現示例的文章就介紹到這了,更多相關python淘寶準點秒殺內容請搜索腳本之家以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持腳本之家!
您可能感興趣的文章:- Unity打開淘寶app并跳轉到商品頁面功能的實現方法
- 備戰618!用Python腳本幫你實現淘寶秒殺
- python 利用百度API進行淘寶評論關鍵詞提取
- Python 爬取淘寶商品信息欄目的實現
- Python實現淘寶秒殺功能的示例代碼
- 用python爬取分析淘寶商品信息詳解技術篇