使用tweepy TweepError:[{u'message':u'抱歉,该页面不存在。'

2024-04-23 14:32:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用这个code suggested by alecxe来收集字典中每个用户的关注者ID。这是我使用的代码:

networkFile = open(r"xxxxx/network%s.txt"% timestr, "w")
for key, value in accounts_alive_dic.iteritems():
    print ("main: "+key)
    ids = []
    for page in tweepy.Cursor(api.followers_ids, screen_name=accounts_alive_dic[key][0]).pages():
        try:
            ids.extend(page)
            time.sleep(60)
            print(ids)
        except:
            ids=[]
            print("Second loop exception for key "+key)
    for id in ids:
        try:
            print(key+","+str(id)+'\n')
            networkFile.write(key+","+str(id)+'\n')
        except:
            print("Third loop exception for key "+key)

networkFile.close()

不幸的是,在收集了几个追随者的ID后,我收到了以下错误消息:

^{pr2}$

你对造成这个错误的原因有什么看法吗?我怎样才能解决这个问题?非常感谢。在


Tags: keyinloopididsforpageprint
1条回答
网友
1楼 · 发布于 2024-04-23 14:32:29

固定的。问题是有些用户有动态用户名(相当聪明啊?!)。我用用户id而不是用户名解决了这个问题。所以现在这一行来自我之前的代码:

for page in tweepy.Cursor(api.followers_ids,screen_name=accounts_alive_dic[key][0]).pages()

看起来像:

^{pr2}$

希望这能帮到外面的人。在

相关问题 更多 >