一个页面包含10条定位微博,可以利用feed_page=number进行翻页爬取。
<div class=\"WB_feed_type SW_fun S_line2 \" mid=\"3571410952070160\" action-type=\"feed_list_item\">\r\n\t\t\t\t<div class=\"WB_feed_datail S_line2 clearfix\">\r\n\t\t\t<div class=\"WB_face\">代码后开始定位微博信息,前面是周边热门图片信息。
共XXXX条周边微博
以下分别定位字段为,mid,content,locate,geo,date
<div class=\"WB_feed_type SW_fun S_line2 \" mid=\"3571410952070160\"
<\/div>\r\n\t\t\t\t<div class=\"WB_text\" node-type=\"feed_list_content\>+微博内容(例如:这里很堵啊。。。。)
<div class=\"map_data\"><span class=\"W_ico16 icon_locate\"><\/span>+位置信息(例如:浙江省,杭州市,上城区,环城东路 )
- <a href=\"javascript:void(0);\" action-type=\"feed_list_geo_info\" action-data=\"geo=120.183074,30.243961&head=http:\/\/tp3.sinaimg.cn\/2843497510\/50\/40021333668\/1&title=尤文-觉罗-不满族-浙江省,杭州市,上城区,环城东路\">
<a target=\"_blank\" href=\"\/2843497510\/ztXIX8GxG\" title=\"2013-04-26 19:03\" date=\"1366974184000\"
一条微博结束的标志
<\/div>\r\n\t\t\t<\/div>\r\n\t\t<\/div>\r\n\t<\/div>\r\n\t\t \r\n
利用相应标志通过正则式提取需要的字段存进数据库,其中mid用于判重。
数据库表的设计
date类型表示YYYY-MM-DD
datetime类型表示YYYY-MM-DD HH:MM:SS
+-----------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+----------+------+-----+---------+-------+
| mid | char(16) | YES | | NULL | |
| content | blob | YES | | NULL | |
| locate | char(20) | YES | | NULL | |
| longitude | char(10) | YES | | NULL | |
| latitude | char(10) | YES | | NULL | |
| date | datetime | YES | | NULL | |
+-----------+----------+------+-----+---------+-------+
在实践过程过程中发现存入blob的时候中文出现乱码问题,所以改成用text了
+-----------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+----------+------+-----+---------+-------+
| mid | char(16) | YES | UNI | NULL | |
| content | text | YES | | NULL | |
| locate | char(20) | YES | | NULL | |
| longitude | char(10) | YES | | NULL | |
| latitude | char(10) | YES | | NULL | |
| date | datetime | YES | | NULL | |
+-----------+----------+------+-----+---------+-------+
6 rows in set (0.01 sec)