|
一个是获取新浪微博的热议话题一个是获取新浪微博的TOP前十的名单
- import urllib2
- import re
- i=0
- req = urllib2.Request("http://weibo.com/?c=spr_web_sq_baidub_weibo_t001")
- res = urllib2.urlopen(req)
- searchTop=re.compile(r'(\s+)<li><a\s+(.*?)http://huati.weibo.com(.*?)</a></li>')
- html = res.readlines()
- for line in html:
- result=searchTop.match(line)
- if result:
- startindex=result.group().index('">')
- endindex=-9
- print result.group()[startindex+1:endindex].decode('utf8').encode('gb2312')
- res.close()
结果如下
>iPad Mini来了
>刘欢疑退中国好声音
>大小S父亲病逝
>教师穿女仆装引热议
>喜感健眼操姑娘现身
>姚晨自曝已订婚
>女子网购丢包装被杀
>中女子被柬强制下跪
>麦蒂抵青岛引轰动
>湖北氨气泄露事故
>消防车竟起火引热议
>父拒捐骨髓儿病逝
>幼师连打女童70耳光
>俞灏明重回爆炸现场
>何洁自曝新男友
>浪漫满屋2遭吐槽
>专家提高速涨价治堵
>潘基文鸟叔跳骑马舞
>博友高原反应去世
>新娘出嫁戴10斤金饰
>接父母进城要挣8000
>物理教授单手劈断砖
>朝鲜曝自制平板电脑
>霜降吃什么最温暖
>副乡长上非诚灯全灭
>围观大神疯狂刷系统
>电视剧《名媛望族》
>朱茵黄贯中生女
>潘粤明被指霸占房产
>楼粉粉一掰就断
>美国大选最后一辩
>欧冠曼联巴萨大逆转
>李小璐生下一女
>阮经天许玮宁曝同居
>孙燕姿待产晒婴儿房
>李晨回应爱送石头心
>怕打针小宝萌翻网友
>钢管舞国家队成立
>iPad Mini来了
>刘欢疑退中国好声音
- import urllib2
- import re
- i=0
- req = urllib2.Request("http://weibo.com/?c=spr_web_sq_baidub_weibo_t001")
- res = urllib2.urlopen(req)
- searchTop=re.compile(r'(\s+)<li><em\s+(.*?)(\s+)target')
- html = res.readlines()
- for line in html:
- result=searchTop.match(line)
- if result:
- startindex=result.group().index('title="')
- endindex=-7
- print result.group()[startindex+6:endindex].decode('utf8').encode('gb2312')
- res.close()
结果如下
"姚晨"
"小S"
"谢娜"
"王力宏"
"何炅"
"赵薇"
"杨幂"
"陈坤"
"大S"
"蔡康永"
|
|
|
|
|
|
|