微博(APP)榜单爬虫及数据可视化

2871
1

江湖人称潇洒哥 数据达人Lv4

发表于2018-8-16 21:57

楼主





前言
今天继续APP爬虫,今天爬取的是微博榜单(24小时榜)的数据,采集的字段有:
  • 用户id
  • 用户地区
  • 用户性别
  • 用户粉丝
  • 微博内容
  • 发布时间
  • 转发、评论和点赞量
该文分以下内容:
  • 爬虫代码
  • 用户分析
  • 微博分析










爬虫代码import requests import json import re import time import csv headers = { 'Host': 'api.weibo.cn', 'Connection': 'keep-alive', 'User-Agent': 'Weibo/29278 (iPhone; iOS 11.4.1; Scale/2.00)' } f = open('1.csv','w+',encoding='utf-8',newline='') writer = csv.writer(f) writer.writerow(['user_id','user_location','user_gender','user_follower','text','created_time','reposts_count','comments_count','attitudes_count']) def get_info(url): res = requests.get(url,headers=headers) print(url) datas = re.findall('"mblog".*?),"weibo_position"',res.text,re.S) for data in datas: json_data = json.loads(data+'}') user_id = json_data['user']['name'] user_location = json_data['user']['location'] user_gender = json_data['user']['gender'] user_follower = json_data['user']['followers_count'] text = json_data['text'] created_time = json_data['created_at'] reposts_count = json_data['reposts_count'] comments_count = json_data['comments_count'] attitudes_count = json_data['attitudes_count'] print(user_id,user_location,user_gender,user_follower,text,created_time,reposts_count,comments_count,attitudes_count) writer.writerow([user_id,user_location,user_gender,user_follower,text,created_time,reposts_count,comments_count,attitudes_count]) time.sleep(5) if>




接着对地区进行数据处理,进行统计。可以看出,位于北京的用户是最多的(大V都在北京)。
df['location'] = df['user_location'].str.split(' ').str[0]




接下来看下用户的性别比例:男性用户占多。





最后再看看上榜大V粉丝前十:





微博分析
首先,对时间数据进行处理,取出小时时间段。





接着,我们看看微博点赞前十的用户。





最后,绘制微博文章词云图。







最近看过此主题的会员

esen_4XJGK5ZGMF

godhhl

45482603

esen007

leiz

曦文

a1ex

admin

大哥很IT

韦韬然

韩立

我De骄傲

小亿

1个回答

只看楼主

韦韬然 数据老手Lv5

发表于2018-8-17 10:22

只看该作者

取消 关注该作者的回复

沙发

登录后可回答问题,请登录注册

快速回复 返回顶部 返回列表

小时

全天响应

分钟

快速处理问题

工程师强势助力

明星产品
解决方案
联系合作

400咨询:400-0011-866

技术支持QQ:400-0011-866(工作日9:00-18:00)

产品建议邮箱yixin@esensoft.com

关注我们

扫TA学习更多干货

一对一专家交流

版权所有© 2006-2024 北京亿信华辰软件有限责任公司 京ICP备07017321号 京公网安备11010802016281号