实时获取淘宝时间
實時獲取淘寶時間
如今啥東西都搞饑餓營銷,啥都要搶,而且搶的人還不少,一旦晚一秒就很難搶到了,本人在經歷了好幾個月的搶手機搶鞋失敗后,終于意識到自己手機的時間跟淘寶不一樣!!手機時間比淘寶慢了一秒,這就導致我卡點進去的時候已經比別人慢了,那要如何獲得淘寶的實時時間呢,在網上找到了一個python寫的實時顯示淘寶時間的代碼,在此分享給大家,有想卡點搶東西的一定要看平臺服務器的時間!經過不斷摸索,發現有兩種方法可以實現。
Python代碼1
import requests import time import tkinterdef funcname():r1 = requests.get(url='http://api.m.taobao.com/rest/api3.do?api=mtop.common.getTimestamp',headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 UBrowser/6.2.4098.3 Safari/537.36'})x = eval(r1.text)timeNum = int(x['data']['t'])timeStamp = float(timeNum/1000)timeArray = time.localtime(timeStamp)otherStyleTime = time.strftime("%H:%M:%S", timeArray)return otherStyleTimedef tick():global time1# 獲取時間time2 = funcname()# 如果時間發生變化,代碼自動更新顯示的系統時間if time2 != time1:time1 = time2clock.config(text=time2)# calls itself every 200 milliseconds# to update the time display as needed# could use >200 ms, but display gets jerkyclock.after(200, tick)win = tkinter.Tk() win.title("獲取淘寶服務器時間") time1 = '' clock = tkinter.Label(win, font=('times', 100, 'bold'), bg='green') clock.grid(row=0, column=0) tick() win.mainloop()Python代碼2
import tkinter import http.client import timedef get_webservertime(host):conn = http.client.HTTPConnection(host)conn.request("GET", "/")r = conn.getresponse()ts = r.getheader('date') # 獲取http頭date部分# 將GMT時間轉換成北京時間ltime = time.strptime(ts[5:25], "%d %b %Y %H:%M:%S")ttime = time.localtime(time.mktime(ltime) + 8 * 60 * 60)dat = "%u-%02u-%02u" % (ttime.tm_year, ttime.tm_mon, ttime.tm_mday)tm = "%02u:%02u:%02u" % (ttime.tm_hour, ttime.tm_min, ttime.tm_sec)return tmdef tick():global time1# 獲取時間time2 = get_webservertime('www.taobao.com')# 如果時間發生變化,代碼自動更新顯示的系統時間if time2 != time1:time1 = time2clock.config(text=time2)# calls itself every 200 milliseconds# to update the time display as needed# could use >200 ms, but display gets jerkyclock.after(200, tick)win = tkinter.Tk() win.title("獲取淘寶服務器時間") time1 = '' clock = tkinter.Label(win, font=('times', 100, 'bold'), bg='green') clock.grid(row=0, column=0) tick() win.mainloop()總結
- 上一篇: [html] 说说你对target=“
- 下一篇: [html] title与h1的区别、