這個不能實現毫秒級的一個秒殺,只能實現一種自動化。重要的事情再說一便只能實現自動化,根本搶不到。現在都是用伺服器搶了。 話不多說,給大家發一遍程式碼,僅供學習參考: #-*- coding:utf-8 -*-
@Author: A dog
PS:如有需要Python學習資料的小夥伴可以加點選下方連結自行獲取
@File: Taobao.py@Software: PyCharmimport datetime import time
from selenium import webdriver
name = ‘賬號’ password = ‘密碼’
指定webdriver位置driver = webdriver.Chrome(executable_path=‘C:\chromedriver.exe’)
開啟淘寶網址driver.get(‘https://www.taobao.com/’)
class pay: # 登入模組 def login_in(self, num, pwd, times): # 點選登入 driver.find_element_by_class_name(‘h’).click() time.sleep(0.3) # 傳送賬號密碼 driver.find_element_by_id(‘fm-login-id’).send_keys(num) driver.find_element_by_id(‘fm-login-password’).send_keys(pwd) time.sleep(0.2) # 點選登入 driver.find_element_by_class_name(‘fm-btn’).click() time.sleep(1) # 進入購物車 driver.get(“https://cart.taobao.com/cart.htm”) # driver.find_element_by_id(‘mc-menu-hd’).click() # time.sleep(0.2) driver.find_element_by_id(‘J_SelectAll1’).click() time.sleep(0.5) self.auto_check1(times)
#反覆結算def auto_check(self,times): while True: try: if driver.find_element_by_id('J_SelectAll1'): driver.find_element_by_id('J_SelectAll1').click() time.sleep(0.5) break except: time.sleep(0.5) pass while True: if datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') >= times: while True: try: driver.find_element_by_id("J_Go").click() print("成功結算") driver.find_element_by_link_text('提交訂單').click() print(f"搶購成功,請儘快付款") time.sleep(5) return 0 except: print("無法結算,重試") time.sleep(1) driver.get("https://cart.taobao.com/cart.htm") self.auto_check(times)def auto_check1(self,times): while True: if datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f') >= times: while True: try: driver.find_element_by_id("J_Go").click() print("成功結算") driver.find_element_by_link_text('提交訂單').click() print(f"搶購成功,請儘快付款") time.sleep(5) return 0 except: print("無法結算,重試") time.sleep(1) driver.get("https://cart.taobao.com/cart.htm") self.auto_check(times)# 執行def run_driver(self, num, pwd, times): self.login_in(num, pwd, times)
qq:
if name == ‘main’: jd = pay() jd.run_driver(name, password, ‘2020-12-15 19:59:59:400’)
如果有需要代搶的可以聯絡我,程式碼中執行下面聯絡fangsh