python爬微博粉丝_Python爬虫:微博粉丝列表

importrequestsimportre

tmpt_url= 'https://weibo.com/p/1005051678105910/follow?page=%d#Pl_Official_HisRelation__59'

defget_data(tmpt_url):

urllist= [tmpt_url%i for i in range(1,6)]

user_id= [] #粉丝ID

user_name = [] #粉丝名称

user_follow = [] #粉丝的关注

user_fans = [] #粉丝的粉丝量

user_address = [] #粉丝的地址

headers= {'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8','Accept-Encoding':'gzip, deflate, br','Accept-Language':'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2','Connection':'keep-alive','Cookie':'请在自己的浏览器中查看,因涉及个人隐私不公开','Host':'weibo.com','Upgrade-Insecure-Requests':'1','User-Agent':'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:65.0) Gecko/20100101 Firefox/65.0'}for url inurllist:

html= requests.get(url,headers=headers).text

user_id.extend(re.findall(r'\S+<\\/a>',html))

user_name.extend(re.findall(r'(\S+)<\\/a>',html))

user_follow.extend(re.findall(r'关注 (\d+)<\\/a>',html))

user_fans.extend(re.findall(r'粉丝(\d+)<\\/a>',html))

user_address.extend(re.findall(r'地址<\\/em>(\S+\s?\S+?)<\\/span>\\r\\n\\t\\t\\t\\t\\t<\\/div>',html))print('user_id',user_id)print('user_name',user_name)print('user_follow',user_follow)print('user_fans',user_fans)print('user_address',user_address)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值