python+selenium小米商城紅米K40手機(jī)自動搶購的示例代碼
使用環(huán)境
1、python3
2、selenium
selenium使用簡述
1、安裝selenium
pip install selenium
2、安裝ChromeDriver
下載地址:http://chromedriver.storage.googleapis.com/index.html
注意:下載的ChromeDriver需要與Chrome版本一致。
1)Chrome版本查看:

2)ChromeDriver對應(yīng)版本下載:

3)ChromeDriver下載后解壓到任意文件夾,建議可以放到項(xiàng)目目錄中,拷貝chromedriver可執(zhí)行文件的路徑,代碼中需要用到:
代碼實(shí)現(xiàn)
from selenium import webdriver
import time
import datetime
class XiaoMi():
def __init__(self):
self.name = "" #登陸小米商城用戶名
self.pwd = "" #登陸小米商城密碼
self.buytime = "2021-03-12 10:00:00" # 指定秒殺時間,并且開始等待秒殺
self.chrome_driver = "" #chromedriver的文件位置 例如:self.chrome_driver = 'C:/Desktop/lib/chromedriver.exe'
self.browser = webdriver.Chrome(executable_path = self.chrome_driver)
def login(self):
self.browser.get('https://account.xiaomi.com/') # 登錄網(wǎng)址
time.sleep(2)
self.browser.find_element_by_name("account").send_keys(self.name)
self.browser.find_element_by_name("password").send_keys(self.pwd)
self.browser.find_element_by_xpath('//*[@type="submit"]').click()
time.sleep(3)
#搶購紅米K40
self.buy_on_time()
#搶手機(jī)紅米K40
def buy_on_time(self):
self.browser.get("https://www.mi.com/buy/detail?product_id=13544") # 切換到秒殺頁面
time.sleep(2)
self.browser.find_element_by_xpath('//div[@class="sale-btn"]/a').click() # 再次登陸
time.sleep(2)
self.browser.find_element_by_xpath("http://div[@class='option-box']/ul/li[4]").click() # 選擇12G+256G版本
print('登錄成功,正在等待搶購···')
while True: # 不斷刷新時鐘
now = datetime.datetime.now()
if now.strftime('%Y-%m-%d %H:%M:%S') == self.buytime:
self.browser.find_element_by_xpath('//div[@class="sale-btn"]/a').click() # 購買按鈕的Xpath
print('下單成功,請抓緊付款!')
time.sleep(0.01) # 注意刷新間隔時間要盡量短
if __name__ == '__main__':
MS = XiaoMi()
MS.login()
到此這篇關(guān)于python+selenium小米商城紅米K40手機(jī)自動搶購的示例代碼的文章就介紹到這了,更多相關(guān)python+selenium自動搶購內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Python?OpenCV中cv2.minAreaRect實(shí)例解析
minAreaRect的主要作用是獲取一個多邊形(就是有很多個點(diǎn)組成的一個圖形)的最小旋轉(zhuǎn)矩形(旋轉(zhuǎn)矩形就是我們平常見到的水平框帶了角度),這篇文章主要給大家介紹了關(guān)于Python?OpenCV中cv2.minAreaRect的相關(guān)資料,需要的朋友可以參考下2022-11-11
通過mod_python配置運(yùn)行在Apache上的Django框架
這篇文章主要介紹了通過mod_python配置運(yùn)行在Apache上的Django框架,Django是最具人氣的Python web開發(fā)框架,需要的朋友可以參考下2015-07-07
python虛擬機(jī)pyc文件結(jié)構(gòu)的深入理解
這篇文章主要為大家介紹了python虛擬機(jī)之pyc文件結(jié)構(gòu)的深入探究理解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-03-03
Pytorch+PyG實(shí)現(xiàn)GraphSAGE過程示例詳解
這篇文章主要為大家介紹了Pytorch+PyG實(shí)現(xiàn)GraphSAGE過程示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-04-04
python射線法判斷檢測點(diǎn)是否位于區(qū)域外接矩形內(nèi)
這篇文章主要為大家詳細(xì)介紹了python射線法判斷檢測點(diǎn)是否位于區(qū)域外接矩形內(nèi),具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-06-06

