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,python,爬虫,淘宝时间)