利用rwda包抓取微博评论并分析
来源:互联网 发布:java热血征途2008安卓 编辑:程序博客网 时间:2024/06/06 01:38
工具:Rstudio,R(3.3.4)
install.packages("devtools")library(devtools)devtools::install_github("sjhfx/rwda")library(RCurl)library(bitops)library(rjson)library(jiebaR)library(jiebaRD)library(wordcloud2)library(vioplot)library(sm)library(curl)library(plyr)library(rwda)access_token<-"your access_token here"#you can get it in http://open.weibo.com/tools/consoleweiboid="/the mid of post"#you can find it by #1, click the time under the weibo user name at the specific post,enter the page for details;#2, click the right mouse button to view the source code;#3, search "mid =", there is a string of numbers behind it,that's what we need#由于微博对个人开发者一次抓取评论数量有限制,大概在2000条(每页50条),对包里的get_comments函数进行改进,使其可以自行设置起始页数与终结页数get_com<-function (access_token, weiboid, spage,epage) { comments = list() df_comments = ldply(comments, get_fields, .id = NULL) page = spage while (page <= epage) { url = paste("https://api.weibo.com/2/comments/show.json?id=", weiboid, "&page=", page, "&access_token=", access_token, sep = "") comments = fromJSON(getURL(url, .opts = list(ssl.verifypeer = FALSE)))$comments print(paste("Page", page, ": ", length(comments), "comments")) df_comments = rbind(df_comments, ldply(comments, get_fields, .id = NULL)) page = page + 1 Sys.sleep(1) } return(df_comments)}dat<-get_com(access_token,weiboid,spage=40,epage=80)getwd()write.table(dat,file="C:/Users/andy/Documents/weibo_comments.csv")##subset the rows contains keywordshead(dat)n=grep("\keywords",dat$text)#get the index of rows that contain keywordsdat_key=dat[n,]##create a wordcloud graph weibo_cloud(dat, stopwords = c("心心", "回复","哈哈","/doge"))
参考文章:
- R微博数据分析
- 用R爬取微博评论数据
阅读全文
0 0
- 利用rwda包抓取微博评论并分析
- python抓取新浪微博评论并分析
- Java抓取新浪微博及评论
- 应用Wireshark抓取HTTP数据包并分析包内内容
- 利用libpcap库函数 ------抓取一个包 ,并打印包的长度
- 抓取手机数据网络的网络包(二)——抓取网络包,并使用wireshark分析
- 网页数据抓取并分析
- 利用python抓取搜狗关于数据分析的文章并保存到csv文件
- python 抓取腾讯微博数据并做简单的分析
- python 抓取腾讯微博数据并做简单的分析 .
- 利用libpcap局域网内抓取arp包
- 利用Android手机抓取蓝牙日志包
- 手机利用charles抓取https请求包
- 利用Android手机抓取蓝牙日志包
- 如何科学地蹭热点:用python爬虫获取热门微博评论并进行情感分析
- (python)热门话题的某些微博评论和转发数的抓取
- 抓取腾讯新闻评论
- 虎扑网评论基础抓取
- FPGA作业二
- 使用Anaconda配置环境
- LayoutInflater 和LayoutParams一起实现动态添加控件
- 二逼平衡树(线段树套Splay)
- echarts莫名缩小,并且宽度不能更改,生成时默认宽度
- 利用rwda包抓取微博评论并分析
- 数据库笔记2————关系数据库(关系代数)
- Looper.loop死循环为什么不会卡死
- 使用QT C++开发生成二维码
- C++程序设计案例实训教程第7章
- Badboy自动化测试工具8 Incrementing Variables
- 订单管理控制层
- NOIP2013货车运输
- JAVA后台 关于如何从后台传递信息在jsp前端页面显示