12306搶票軟體

2021-10-19 14:41:16 字數 1496 閱讀 1014

import json,time

# 讀寫資料庫中的票數

defwr_info

(sign,dic=

none):

if sign ==

"r":

with

open

("ticket"

,mode=

"r",encoding=

"utf-8"

)as fp:

dic = json.load(fp)

return dic

elif sign ==

"w":

with

open

("ticket"

,mode=

"w",encoding=

"utf-8"

)as fp:

json.dump(dic,fp)

# res = wr_info("r")

# print(res)

# dic =

# wr_info("w",dic)

# 搶票方法

defget_ticket

(person)

:# 獲取資料庫中實際的票數

dic = wr_info(

"r")

print

(dic)

# 模擬一下網路延遲

time.sleep(

0.5)

# 判斷票數

if dic[

"count"

]>0:

print

("%s搶到票了"

%(person)

) dic[

"count"]-=

1 wr_info(

"w",dic)

else

:print

("%s沒有搶到這張票"

%(person)

)def

run(person,lock)

:# 檢視剩餘票數

dic = wr_info(

"r")

print

("%s 查詢票數: %s"

%(person , dic[

"count"])

)# 上鎖

lock.acquire(

)# 開始搶票

get_ticket(person)

lock.release(

)if __name__ ==

"__main__"

: lock = lock(

) lst =

["科比"

,"麥迪"

,"高峰"

,"姚明"

,"鄧肯"

,"成龍"

,"劉亦菲"

]for i in lst:

p = process(target=run,args=

(i,lock)

) p.start(

)

12306搶票一(登入)

找到登入的頁面,由於賬號密碼登入比較麻煩就直接掃碼登入所以要先找到登入頁面的url,利用selenium進行登入。在實戰中一般要先把框架給搭好,好後面新增 為了 得簡潔,可讀性較高,所以整個過程在乙個類中實現,類中又定義了不同的函式來實現不同的功能 搭框架 有乙個執行的入口,有乙個主函式可以呼叫定義...

關於12306搶票指令碼記錄

1.首先從如何查票開始做 qeury ticket.py獲取車次在程式中的簡寫 station.py 查詢車票 station.py coding utf 8 該檔案主要是獲取車站的資訊 import re,requests from requests.packages.urllib3.except...

Python操作12306搶票指令碼

首先,我需要的工具和元件有 基本的配置已完成,測試一下,cmd下執行python,分別鍵入以下指令 這個時候大家可能會遇到一些 情況 chromedriver.exe程序 會經常關閉 解決辦法 chrome 版本第一點 52.xx.xx就可以 然後 去找對應版本的 chromedriver 還有遇到...