# 然后是抓取数据的函数。目前只写了feeds部分的抓取,其他是类似的,而且会更简单一点,不需要刷新页面。
f_weibo_get
# 参数N是想要获取的微博条数。参数hisnick是对方的ID
library(rjson)
memory.limit(4000)
# 先看一下有多少页
pg=1
the1url
the1get
write(the1get, "temp.txt")
the1get
idi
oid
oid
idi
uid
uid
# 微博信息
infoi
a1 STK && STK.pageletM && STK.pageletM.view\\(','',the1get[infoi])
a1 ','',a1)
a1
write(a1, 'a1.txt')
a1
numberi ', a1))
number ')[[1]][2]
number ')[[1]][1]
pages
weibo_data
# 循环读取页面
for (pg in 1:pages){
# 第一屏
the1url
the1get
write(the1get, "temp.txt")
the1get
# 看别人的时候是hisFeed,看自己的时候是myFeed(后面的url也略有差异,主要是刷新的时候需要用到uid)
if(uid == oid){
myfeedi
}
if(uid != oid){
myfeedi
}
a1 STK && STK.pageletM && STK.pageletM.view\\(','',the1get[myfeedi])
a1 ','',a1)
a1
write(a1, 'a1.txt')
a1
# 最后一条微博的ID
lastmidi
lastmid
lastmid
# 于是第二屏
the2url
'&count=15&max_id=', lastmid, '&pre_page=', pg, '&end_id=&pagebar=0&uid=', oid, sep='')
the2get
write(the2get, "temp.txt")
the2get
a2
write(a2, 'a2.txt')
a2
# 最后一条微博的ID
lastmidi
lastmid
lastmid
# 于是第三屏
the3url
'&count=15&max_id=', lastmid, '&pre_page=', pg, '&end_id=&pagebar=1&uid=', oid, sep='')
the3get
write(the3get, "temp.txt")
the3get
a3
write(a3, 'a3.txt')
a3
# 筛选微博正文内容,连接起来
a123
index
a11
b [^<>]*
getcontent
paste(substring(string, greg+1, greg+attr(greg,'match.length')-2), collapse=' ')
}
a111
names(a111)
weibo_data
gc()
}
# 去掉英文和数字,去掉@对象
weibo_data
weibo_data
return(weibo_data[1:min(as.numeric(number), N)])
}
# 登录
ch0
ch1
# 获取微博数据(这里只做了我自己的版本,10000是个足够大的数字)
weibo_10000_0
weibo_10000_1
# 这两个结果有一点点点差异,目前看来,貌似是显示给自己的微博比较全。
all(weibo_10000_0 %in% weibo_10000_1)
# FALSE
all(weibo_10000_1 %in% weibo_10000_0)
# TRUE