一:通过前一篇文章的方法提取热门话题,由于蛋疼的新浪wei~b~o~Api开发的太少,申请高级接口也很墨迹==,博主弄了好久没申请成功。自己只能通过热门话题搜索得到url,
然后爬数据,抓取发布微博的用户,以及对应微博的转发数和评论列表
二:例子:热门话题:“男生也来大姨妈”
result = urllib2.urlopen('http://s.weibo.com/weibo/%E7%94%B7%E7%94%9F%E4%B9%9F%E6%9D%A5%E5%A4%A7%E5%A7%A8%E5%A6%88&xsort=hot&Refer=hotmore')#打开你得到的url
res = result.read()
reg3 = re.compile(r'<p class=\\"comment_txt\\" node-type=\\"feed_list_content\\" nick-name=\\"(?P<name>.+?)\\">')#通过审查元素列出正规表达式,提取微博昵称
content = re.findall(reg3, res)
print content
print len(content)
#通过审查元素列出正规表达式,提取转发和评论数
<pre class="python" name="code">reg4 = re.compile(r'<ul class=\\"feed_action_info feed_action_row4\\">.+?<li>.+?<\\/li>.+?<li><a .+?><span .+?>.+?<em>(.+?)<\\/em><\\/span><\\/a><\\/li>.+?<li><a .+?><span .+?>.+?<em>(.+?)<\\/em><\\/span><\\/a><\\/li>.+?<li><a .+?><span .+?<\\/span><\\/a><\\/li>')
amount = re.findall(reg4, res)
print amountprint
len(amount)
结果如图:
解码一下昵称;这里由于得到的格式原因,无法轻快的用python print 得到汉字。所以只能借助解码工具。。希望有大神看到,能给个指导。
最后,我真想再吐槽一下xin浪的API接口,真是太让人失望了。各种没权限。开发的那些也都是亚美蝶的。看来挖掘机之路不好走,楼主得学好爬虫了。