gpt4 book ai didi

python - 使用json获取所有 "viewer"和 "timestamp"

转载 作者:行者123 更新时间:2023-11-30 23:29:35 26 4
gpt4 key购买 nike

我正在尝试使用 json.loads 获取所有“查看器”和“时间戳”并获取它以输出它们。在一个网址中,但一直坚持这样做。这是代码:

elif used_prefix and cmd == "tracker" and self.getAccess(user) >= 1:
try:
if len(args) == 0:
f = urlreq.urlopen("http://chtracker.info/index.py?output=html&x=page&y={}&results=0".format(user.name))
data = json.loads(f.readall().decode("utf-8"))
viewers = [(item['viewer'], item2['timestamp']) for item, item2 in data]
room.message("The last 10 people who visited your profile: %s %s ago".format(item, stamp.getTimeStamp(item2)))
except:
room.message((str(sys.exc_info()[1])))

URL 中的内容如下:

[{"viewer": "terraria11218", "timestamp": "1389575253.25377", "referer": "http://www.animefave.net/my-little-sister-cant-be-this-cute-season-2-episode-1/", "ip": "108.14.254.110", "useragent": "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36", "page": "mechabot"}, {"viewer": "oruni", "timestamp": "1389574404.94542", "referer": "http://www.pinoyanime.tv/btooom-episode-3/", "ip": "75.187.235.72", "useragent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.72 Safari/537.36", "page": "mechabot"}

最佳答案

看起来你可以做这样的事情:

>>> viewers = [(item['viewer'], item['timestamp']) for item in data]
[('terraria11218', '1389575253.25377'), ('oruni', '1389574404.94542')]
>>> viewers
[('terraria11218', '1389575253.25377'), ('oruni', '1389574404.94542')]

假设列表中的每个字典都有键“viewer”和“timestamp”。

关于python - 使用json获取所有 "viewer"和 "timestamp",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21082709/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com