print("正在爬取中...") for i in tqdm(range(max-1)): # for i in range(max - 1): time.sleep(random.uniform(1.0, 3.0)) comment_url = "https://m.weibo.cn/comments/hotflow?id=" + id + "&mid=" + mid + "&max_id=" + str(max_id) + "&max_id_type=" + str(max_id_type) if(dic["max_id"]!=0): dic = getCommentTnfo(comment_url) max_id = dic["max_id"] max_id_type = dic["max_id_type"] comment_list = comment_list + dic["comment_list"]
# 是否预览 preview = input("共" + str(len(comment_list)) + "条记录,预览(y/n):") if (preview == "y"or preview == "Y"): for comment in comment_list: print(comment)
# 是否保存 save = input("共" + str(len(comment_list)) + "条记录,保存(y/n):") if (save == "y"or save == "Y"): print("正在写入中...") withopen("comment.txt", "w", encoding="utf-8") as f: for comment in tqdm(comment_list): f.writelines(comment + "\n")
if __name__ == '__main__': while (True): print("-------微博评论爬虫-------") print(" by liangyue") getcomments()
# 是否预览? preview = input("共" + str(len(list_dic_blog)) + "条记录,你是否希望预览(y/n):") if (preview == "y"or preview == "Y"): for dic_blog in list_dic_blog: print(dic_blog)
# 是否保存? save = input("共" + str(len(list_dic_blog)) + "条记录,保存到blog.txt(y/n):") if (save == "y"or save == "Y"): withopen("blog.txt", "w", encoding='Utf-8') as f: for dic_blog in tqdm(list_dic_blog): f.writelines(str(dic_blog) + "\n")
if __name__ == '__main__': print("-------微博帖子-------") print(" By liangyue") while(True): getblog()