爬虫目标
通过微博话题获取发帖的信息与用户基本信息,数据可用于该话题的用户分析。
爬取字段:账号id号、昵称、关注数、粉丝数、微博数、个性签名、账号类型、等级、简介、使用设备
所用到模块:requests、lxml、re
说明:无登录爬取微博用户数据,实现 自动获取Cookie和Cookie失效自动更新,还有其他技巧,自己看。
爬虫结构
class WeiBoSpider(): def __init__(self): # 起始地址 self.url = "https://s.weibo.com/weibo?q=%23%E8%94%A1%E5%BE%90%E5%9D%A4%E7%82%B9%E8%AF%84%23&Refer=top" # cookie self.cookie = self.get_cookie() # 获取所有数据 def get_data(self): pass # 通过 id 获取用户信息 def get_user_data(self,user_id): pass # 获取 & 更新 Cookie def get_cookie(self):