欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python獲取淘寶服務器時間的代碼示例

 更新時間:2021年04月22日 08:39:29   作者:sixk  
這篇文章主要介紹了python獲取淘寶服務器時間的代碼示例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧

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

代碼

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)

結果

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】獲取服務器時間

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時間轉換成北京時間
    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)
    #打印出遠程服務器返回的header信息
    #print (response.info())
    header=response.info()
  
    ts=header._headers[1][1]
     
    #將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)
    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時間轉換成北京時間
    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
          
    #打印出遠程服務器返回的header信息
    ts=header._headers[1][1]
    #將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)
    timeStr=dat+' '+tm
    return timeStr

到此這篇關于python獲取淘寶服務器時間的代碼示例的文章就介紹到這了,更多相關python獲取淘寶服務器時間 內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

  • numpy求矩陣的特征值與特征向量(np.linalg.eig函數用法)

    numpy求矩陣的特征值與特征向量(np.linalg.eig函數用法)

    這篇文章主要介紹了numpy求矩陣的特征值與特征向量(np.linalg.eig函數用法),具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-02-02
  • Bottle框架中的裝飾器類和描述符應用詳解

    Bottle框架中的裝飾器類和描述符應用詳解

    這篇文章主要介紹了Bottle框架中的裝飾器類和描述符應用詳解,具有一定參考價值,需要的朋友可以了解下。
    2017-10-10
  • Flask框架中request、請求鉤子、上下文用法分析

    Flask框架中request、請求鉤子、上下文用法分析

    這篇文章主要介紹了Flask框架中request、請求鉤子、上下文用法,結合實例形式分析了flask框架中request、請求鉤子及上下文的功能、用法及相關操作注意事項,需要的朋友可以參考下
    2019-07-07
  • python之當你發(fā)現QTimer不能用時的解決方法

    python之當你發(fā)現QTimer不能用時的解決方法

    今天小編就為大家分享一篇python之當你發(fā)現QTimer不能用時的解決方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-06-06
  • Python?迭代器Iterator詳情

    Python?迭代器Iterator詳情

    這篇文章主要介紹了Python?迭代器Iterator詳情,迭代器可以幫助我們解決面對復雜的數據場景時,快速簡便的獲取數據,下文關于其詳細介紹,需要的小伙伴可以參考一下
    2022-05-05
  • 微信跳一跳python輔助腳本(總結)

    微信跳一跳python輔助腳本(總結)

    本篇文章為大家整理了關于微信跳一跳的輔助腳本內容,這次我們給大家整理的是關于python的腳本內容,一起來學習下。
    2018-01-01
  • python入門之基礎語法學習筆記

    python入門之基礎語法學習筆記

    學習python過程中需要了解的一些基礎語法特整理一下方便更開始接觸python的朋友
    2020-02-02
  • Python讀取文件比open快十倍的庫fileinput

    Python讀取文件比open快十倍的庫fileinput

    fileinput是Python的內置模塊,但不少人對它都是陌生的。今天把fileinput的所有的用法、功能進行詳細的講解,并列舉一些非常實用的案例,對于理解和使用它可以說完全沒有問題
    2021-10-10
  • python實現兩個dict合并與計算操作示例

    python實現兩個dict合并與計算操作示例

    這篇文章主要介紹了python實現兩個dict合并與計算操作,結合具體實例形式分析了Python使用collections.Counter進行字典dict合并與遍歷輸出相關操作技巧,需要的朋友可以參考下
    2019-07-07
  • Python線程之定位與銷毀的實現

    Python線程之定位與銷毀的實現

    這篇文章主要介紹了Python線程之定位與銷毀的實現,小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2019-02-02

最新評論