python獲取淘寶服務(wù)器時間的代碼示例
然但是,這個只能獲取到秒,沒法到毫秒。我暫時不知道該咋解決
代碼
import requests
import time
while True:
class timeTaobao(object):
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'])
def funcname():
timeStamp = float(timeTaobao.timeNum/1000)
timeArray = time.localtime(timeStamp)
otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
return otherStyleTime
t = timeTaobao.funcname()
print(t)
結(jié)果
2021-04-20 15:30:04
2021-04-20 15:30:04
2021-04-20 15:30:04
2021-04-20 15:30:04
2021-04-20 15:30:04
2021-04-20 15:30:05
2021-04-20 15:30:05
2021-04-20 15:30:05
2021-04-20 15:30:05
2021-04-20 15:30:05
2021-04-20 15:30:05
補充:【Python】獲取服務(wù)器時間
import http.client
import time
import os
def get_webservertime(host):
conn=http.client.HTTPConnection(host)
conn.request("GET", "/")
r=conn.getresponse()
#r.getheaders() #獲取所有的http頭
ts= r.getheader('date') #獲取http頭date部分
print(ts)
#將GMT時間轉(zhuǎn)換成北京時間
ltime= time.strptime(ts[5:25], "%d %b %Y %H:%M:%S")
print(ltime)
ttime=time.localtime(time.mktime(ltime)+8*60*60)
print(ttime)
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)
print (dat,tm)
os.system(dat)
os.system(tm)
get_webservertime('www.jd.com')
import urllib.request
import time
def get_webservertime(url):
#返回一個對象
response=urllib.request.urlopen(url)
#打印出遠程服務(wù)器返回的header信息
#print (response.info())
header=response.info()
ts=header._headers[1][1]
#將GMT時間轉(zhuǎn)換成北京時間
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)
print (dat,tm)
get_webservertime('https://www.jd.com/')
import http.client
import time
def get_webservertime(host):
while True:
try:
conn=http.client.HTTPConnection(host)
conn.request("GET", "/")
r=conn.getresponse()
ts= r.getheader('date') #獲取http頭date部分
break
except Exception as e:
print(e)
continue
#將GMT時間轉(zhuǎn)換成北京時間
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)
timeStr=dat+' '+tm
return timeStr
url='www.jd.com'
while True:
print(get_webservertime(url))
def get_webservertime():
url='https://ai.jd.com/jdip/useripinfo.php?callback=jsonpCallbackUserIpInfo'
while True:
try:
response=urllib.request.urlopen(url)
header=response.info()
break
except Exception as e:
print(e)
time.sleep(1)
continue
#打印出遠程服務(wù)器返回的header信息
ts=header._headers[1][1]
#將GMT時間轉(zhuǎn)換成北京時間
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)
timeStr=dat+' '+tm
return timeStr
到此這篇關(guān)于python獲取淘寶服務(wù)器時間的代碼示例的文章就介紹到這了,更多相關(guān)python獲取淘寶服務(wù)器時間 內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Python登錄QQ郵箱發(fā)送郵件的實現(xiàn)示例
本文主要介紹了Python登錄QQ郵箱發(fā)送郵件的實現(xiàn)示例,主要就是三步,登錄郵件、寫郵件內(nèi)容、發(fā)送,文中通過示例代碼介紹的非常詳細,需要的朋友們下面隨著小編來一起學習學習吧<BR>2023-08-08
python 的numpy庫中的mean()函數(shù)用法介紹
這篇文章主要介紹了python 的numpy庫中的mean()函數(shù)用法介紹,具有很好對參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-03-03
Python使用Tkinter實現(xiàn)轉(zhuǎn)盤抽獎器的步驟詳解
這篇文章主要介紹了Python使用Tkinter實現(xiàn)轉(zhuǎn)盤抽獎器,,本文分場景通過實例代碼給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2020-01-01
Python中如何優(yōu)雅的合并兩個字典(dict)方法示例
字典是Python語言中唯一的映射類型,在我們?nèi)粘9ぷ髦薪?jīng)常會遇到,下面這篇文章主要給大家介紹了關(guān)于Python中如何優(yōu)雅的合并兩個字典(dict)的相關(guān)資料,文中通過示例代碼介紹的非常詳細,需要的朋友可以參考借鑒,下面來一起看看吧。2017-08-08

