您好,登錄后才能下訂單哦!
本篇文章給大家分享的是有關使用python怎么實現搶購功能,小編覺得挺實用的,因此分享給大家學習,希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。
Python是一種跨平臺的、具有解釋性、編譯性、互動性和面向對象的腳本語言,其最初的設計是用于編寫自動化腳本,隨著版本的不斷更新和新功能的添加,常用于用于開發獨立的項目和大型項目。
#!/usr/bin/python # -*- coding: UTF-8 -*- #made in white-night #coding=utf-8 import re from PyQt5.QtWidgets import * import sys from PyQt5 import QtCore, QtWidgets from selenium import webdriver import datetime import time import threading import wmi class LoginDlg(QDialog): def __init__(self, parent=None): super(LoginDlg, self).__init__(parent) usr = QLabel("請選擇搶購方式:") pwd = QLabel("請輸入搶購時間:") self.lineEdit = QLineEdit("",self) self.lb0 = QLabel("請輸入待搶購網址:", self) self.lbl = QLabel("等待選擇搶購方案", self) self.lb2 = QLabel("機器碼:", self) self.lb3 = QLabel("授權碼:", self) self.lb4 = QLabel("(獲取授權請加群:462510942)", self) self.lb5 = QLabel("(請勿更改機器碼,否則無法授權)", self) self.lineEdit2 = QLineEdit("", self) self.lineEdit1 = QLineEdit("", self) self.combo = QComboBox(self) self.combo.addItem("0、請選擇搶購方案") self.combo.addItem("1、加購物車") self.combo.addItem("2、不加購物車") self.combo.addItem("3、搶購優惠券") # self.lineEdit.move(200,100) self.lb0.move(50, 100) self.lbl.move(50, 150) self.lb2.move(50, 200) self.lb3.move(50, 250) self.lb4.move(250, 250) self.lb5.move(250, 200) self.lineEdit2.move(100, 200) self.lineEdit1.move(100, 250) self.setGeometry(300, 300, 300, 200) self.setWindowTitle('QComboBox') self.show() self.dateTimeEdit = QtWidgets.QDateTimeEdit() self.dateTimeEdit.setGeometry(QtCore.QRect(140, 50, 121, 22)) self.dateTimeEdit.setDateTime(QtCore.QDateTime(QtCore.QDate(2018, 11, 1), QtCore.QTime(9, 0, 0))) self.dateTimeEdit.setObjectName("dateTimeEdit") gridLayout = QGridLayout() gridLayout.addWidget(usr, 0, 0, 1, 1) gridLayout.addWidget(pwd, 1, 0, 1, 1) gridLayout.addWidget(self.lb0, 2, 0, 1, 1) gridLayout.addWidget(self.combo, 0, 1, 1, 3) gridLayout.addWidget(self.dateTimeEdit, 1, 1, 1, 3) gridLayout.addWidget(self.lineEdit, 2, 1, 1, 3) sqBtn = QPushButton("授權") okBtn = QPushButton("確定") cancelBtn = QPushButton("關閉軟件") btnLayout = QHBoxLayout() btnLayout.setSpacing(60) btnLayout.addWidget(okBtn) btnLayout.addWidget(cancelBtn) btnLayout.addWidget(sqBtn) dlgLayout = QVBoxLayout() dlgLayout.setContentsMargins(40, 40, 40, 40) dlgLayout.addLayout(gridLayout) dlgLayout.addStretch(40) dlgLayout.addLayout(btnLayout) self.setLayout(dlgLayout) okBtn.clicked.connect(self.accept) cancelBtn.clicked.connect(self.reject) sqBtn.clicked.connect(self.cpuid) self.setWindowTitle("VN輔助搶購軟件") self.resize(600, 400) self.thread_handle = None def thread_function(self,index): # 需要在線程加一個全局變量的判斷 用于終止死循環 用來切換方案 data = self.cpuid1[2] + self.cpuid1[5] + min(self.cpuid1) + self.cpuid1[-5] + self.cpuid1[1] + self.cpuid1[3] + self.cpuid1[4] + max(self.cpuid1) + self.cpuid1[1] + \ self.cpuid1[-1] + self.cpuid1[-3] + "V" + "N" + self.cpuid1[-2] + self.cpuid1[0] + self.cpuid1[-4] if self.lineEdit1.text() == data and self.lineEdit2.text() == self.cpuid1: if index==0: self.lbl.setText("請選擇搶購方案,然后點擊確定") elif index==1: self.lbl.setText("成功調用加購物車方案") self.gouwubuy() elif index==2: self.lbl.setText("成功調用不加購物車方案") self.buy() else: self.lbl.setText("成功調用搶券方案") self.quanbuy() else: self.lbl.setText("請輸入正確的授權碼") def accept(self): # 線程創建 self.thread_handle = threading.Thread(target=LoginDlg.thread_function,args=(self,self.combo.currentIndex())) self.thread_handle.start() return def gouwubuy(self): browser.get("https://cart.taobao.com/cart.htm") # 點擊購物車里全選按鈕 buyt = self.dateTimeEdit.text() buyti = re.findall(" (.*)",buyt) buytime = buyti[0]+":00.000000" while True: now = datetime.datetime.now().strftime('%H:%M:%S.%f') # 對比時間,時間到的話就點擊結算 if now > buytime: # 點擊結算按鈕 try: if browser.find_element_by_id("J_Go"): browser.find_element_by_id("J_Go").click() except: pass try: if browser.find_element_by_link_text('提交訂單'): browser.find_element_by_link_text('提交訂單').click() now1 = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f') self.lbl.setText("提交訂單時間為:%s"% now1) except: pass def buy(self): browser.get(self.lineEdit.text()) while True: try: if browser.find_element_by_link_text('立即購買'): browser.find_element_by_link_text('立即購買').click() except: pass try: if browser.find_element_by_link_text('提交訂單'): browser.find_element_by_link_text('提交訂單').click() now1 = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f') self.lbl.setText("提交訂單時間為:%s" % now1) break except: pass def quanbuy(self): browser.get(self.lineEdit.text()) while True: now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f') # 對比時間,時間到的話就點擊結算 try: if browser.find_element_by_link_text('立刻搶'): browser.find_element_by_link_text('立刻搶').click() except: pass try: if browser.find_element_by_link_text('點擊領券'): browser.find_element_by_link_text('點擊領券').click() except: pass def cpuid(self): w = wmi.WMI() cpus = w.Win32_Processor() for u in cpus: self.cpuid1 = u.ProcessorId self.lineEdit2.setText(self.cpuid1) 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() time.sleep(3) if __name__ == '__main__': browser = webdriver.Chrome() browser.maximize_window() login() app = QApplication(sys.argv) dlg = LoginDlg() dlg.show() dlg.exec_() app.exit()
以上就是使用python怎么實現搶購功能,小編相信有部分知識點可能是我們日常工作會見到或用到的。希望你能通過這篇文章學到更多知識。更多詳情敬請關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。