一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

腳本之家,腳本語言編程技術(shù)及教程分享平臺!
分類導(dǎo)航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服務(wù)器之家 - 腳本之家 - Python - python獲取淘寶服務(wù)器時間的代碼示例

python獲取淘寶服務(wù)器時間的代碼示例

2021-10-16 10:27sixk Python

這篇文章主要介紹了python獲取淘寶服務(wù)器時間的代碼示例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

然但是,這個只能獲取到秒,沒法到毫秒。我暫時不知道該咋解決

代碼

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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

補(bǔ)充:【Python】獲取服務(wù)器時間

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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')
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import urllib.request
import time
def get_webservertime(url):
   #返回一個對象
    response=urllib.request.urlopen(url)
    #打印出遠(yuǎn)程服務(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/')
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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))
  
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
          
    #打印出遠(yuǎn)程服務(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)容請搜索服務(wù)器之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持服務(wù)器之家!

原文鏈接:https://blog.csdn.net/weixin_48172266/article/details/115909568

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 国产综合成人亚洲区 | 亚洲午夜久久久久国产 | 色依依视频视频在线观看 | 韩国三级动漫 | 欧美干b视频 | 日韩国产成人精品视频 | 丝袜高跟小说 | 狠狠干2017 | 色天天久久| 精品国产福利片在线观看 | 欧美成人手机 | 黑人同学征服教师麻麻 | 美女被上漫画 | 无码国产成人777爽死在线观看 | 午夜A级理论片左线播放 | julia ann全部在线hd | 性xxxx中国| 国产高清视频免费最新在线 | 亚洲网站大全 | 久久香蕉电影 | 美女脱小内内给男生摸j | 成人性生交大片免费看软件 | 亚洲精品乱码久久久久久蜜桃图片 | 色综合久久综精品 | 久见久热 这里只有精品 | 国产精品一二三 | 欧美日韩在线观看一区二区 | 国产精品自在线拍 | 国产精品99久久免费观看 | 91麻豆精品国产片在线观看 | 亚洲高清网站 | 无遮18禁在线永久免费观看挡 | 好湿好紧太硬了我太爽了网站 | 国产日本韩国不卡在线视频 | 日本韩国推理片免费观看网站 | 欧美人禽杂交av片 | 亚洲性视频在线观看 | 色帝国亚洲欧美在线蜜汁tv | 四虎影院免费在线播放 | h版在线观看 | 第一次处破女18分钟 |