Open zyj0301 opened 2 years ago
我自己改了一下代码,在每次爬取的时候将两者关系记录一下就可以了,楼主可以在write_to_txt处进行修改: def write_to_txt(self): with open('user_id_list.txt', 'ab') as f: for user in self.follow_list: f.write((user['uri'] + ' ' + user['nickname'] + '\n').encode( sys.stdout.encoding)) with open('user_relations.txt', 'ab') as f: for user in self.follow_list: f.write((self.user_id + ',' + user['uri'] + '\n').encode( sys.stdout.encoding)) with open('finish_user.txt', 'ab') as f: f.write((self.user_id +'\n').encode( sys.stdout.encoding))
这个没办法区分。如果您想区分,可以每次只获取一个用户的关注,这样txt就是这个用户的,以此类推。