python获取京东服务器的毫秒级时间

  • Post author:
  • Post category:python




效果

在这里插入图片描述



代码

import requests
import datetime

while True:
    class Jingdongtime(object):
        r1 = requests.get(url='https://api.m.jd.com/client.action?functionId=queryMaterialProducts&client=wh5',
                          headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36'})

        x = eval(r1.text)
        timeNum = int(x['currentTime2'])


        def funcname():
            timeStamp = float(Jingdongtime.timeNum) / 1000
            ret_datetime = datetime.datetime.utcfromtimestamp(timeStamp).strftime("%Y-%m-%d %H:%M:%S.%f")
            return ret_datetime

    t = Jingdongtime.funcname()
    print(t)





2023/03/15更新为下面的

思路是一样的,所以就把上面的留下来了

import requests
import datetime

while True:
    class Jingdongtime(object):
        r1 = requests.get(url='https://api.m.jd.com/client.action?functionId=queryMaterialAdverts&client=wh5',
                          headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36'})

        x = eval(r1.text.replace("null", "123456"))
        timeNum = int(x['currentTimeVal'])


        def funcname():
            timeStamp = float(Jingdongtime.timeNum) / 1000
            ret_datetime = datetime.datetime.utcfromtimestamp(timeStamp).strftime("%Y-%m-%d %H:%M:%S.%f")
            return ret_datetime

    t = Jingdongtime.funcname()
    print(t)



参考


python获取淘宝服务器的毫秒级时间



版权声明:本文为weixin_48172266原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。