TypeError:“ builtin_function_or_method”对象无法下标-某些结果有效,然后引发错误?

时间:2019-04-04 15:09:48

标签: json python-3.x counter

我正在尝试编写代码以提取给定tumblr博客上使用的所有标签(只是我的,而不是为了避免刮擦API而不能更广泛地使用),并使用Counter来查看它们的使用频率。我的脚本抛出标题栏中显示的错误。我已经从脚本中删除了API密钥和用户名,但是下面的代码完整了。

#!/usr/bin/env python3

import json
from itertools import count
from urllib.request import urlopen
from collections import Counter

hostname, api_key = "USERNAME", "API_KEY"
url = "https://api.tumblr.com/v2/blog/USERNAME/posts?api_key=API_KEY".format(
    blog=hostname, key=api_key)

for offset in count(step=20):
    r = json.loads(urlopen(url + "&offset=" + str(offset)).read().decode())
    posts = r["response"]["posts"]
    my_list = []
    for post in posts:
        print(post["tags"])
        continue
    c = Counter(post["tags"])
    c['z'] = 0
    print (c)
    print [list(c.elements())]

它拉结果,直到我认为 json偏移量,然后引发错误,但我不确定。我收到了20个结果帖子(超过101,000个帖子),但Counter只计算了20个帖子中的最后一个。我是非常非常新手,也不知道我的错误在哪里。 / p>

0 个答案:

没有答案