Commit 267df575 by [zhangzhiwei]

微博添加排名字段

parent aec57a25
...@@ -32,16 +32,18 @@ public class WeiboHotSearch implements Serializable{ ...@@ -32,16 +32,18 @@ public class WeiboHotSearch implements Serializable{
private int changeCount; //据上分钟变化量 private int changeCount; //据上分钟变化量
private int rank; //排名
public WeiboHotSearch(){} public WeiboHotSearch(){}
public WeiboHotSearch(String url, String name, int count,boolean hot){ public WeiboHotSearch(String url, String name, int count,boolean hot,int rank){
this.id = name + "_" + new Date().getTime(); this.id = name + "_" + new Date().getTime();
this.url = url; this.url = url;
this.name = name; this.name = name;
this.count = count; this.count = count;
this.hot = hot; this.hot = hot;
this.rank = rank;
this.time = new Date(); this.time = new Date();
this.day = TimeParse.dateFormartString(new Date(), "yyyy-MM-dd"); this.day = TimeParse.dateFormartString(new Date(), "yyyy-MM-dd");
} }
...@@ -56,6 +58,7 @@ public class WeiboHotSearch implements Serializable{ ...@@ -56,6 +58,7 @@ public class WeiboHotSearch implements Serializable{
+ ", count = " + count + ", count = " + count
+ ", time = " + time + ", time = " + time
+ ", hot = " + hot + ", hot = " + hot
+ ", rank = " + rank
+ ", day = " + day + ", day = " + day
+ ", changeCount = " + changeCount + ", changeCount = " + changeCount
+ "]"; + "]";
...@@ -130,6 +133,14 @@ public class WeiboHotSearch implements Serializable{ ...@@ -130,6 +133,14 @@ public class WeiboHotSearch implements Serializable{
this.day = day; this.day = day;
} }
public int getRank() {
return rank;
}
public void setRank(int rank) {
this.rank = rank;
}
......
...@@ -66,8 +66,11 @@ public class WeiboHotSearchCrawler { ...@@ -66,8 +66,11 @@ public class WeiboHotSearchCrawler {
String id = "http://s.weibo.com"+element.select("td.td-02").select("a").attr("href"); String id = "http://s.weibo.com"+element.select("td.td-02").select("a").attr("href");
String name = element.select("td.td-02").select("a").text(); String name = element.select("td.td-02").select("a").text();
String num = !element.select("td.td-02").select("span").text().equals("")?element.select("td.td-02").select("span").text():"0"; String num = !element.select("td.td-02").select("span").text().equals("")?element.select("td.td-02").select("span").text():"0";
String rank = !element.select("td[class=\"td-01 ranktop\"]").text().equals("")?element.select("td[class=\"td-01 ranktop\"]").text():"-1";
int hotCount = Integer.valueOf(num); int hotCount = Integer.valueOf(num);
WeiboHotSearch hotSearch = new WeiboHotSearch(id, name, hotCount, true); int rankCount = Integer.valueOf(rank);
WeiboHotSearch hotSearch = new WeiboHotSearch(id, name, hotCount,true, rankCount);
list.add(hotSearch); list.add(hotSearch);
} catch (Exception e) { } catch (Exception e) {
SendMailWeibo.sendMail("微博热搜采集出现问题", "859548429@qq.com"); SendMailWeibo.sendMail("微博热搜采集出现问题", "859548429@qq.com");
...@@ -134,9 +137,10 @@ public class WeiboHotSearchCrawler { ...@@ -134,9 +137,10 @@ public class WeiboHotSearchCrawler {
JSONObject cardInfo = card_group.getJSONObject(j); JSONObject cardInfo = card_group.getJSONObject(j);
String name = cardInfo.getString("desc"); String name = cardInfo.getString("desc");
int hotCount = cardInfo.getIntValue("desc_extr"); int hotCount = cardInfo.getIntValue("desc_extr");
int rankCount = cardInfo.getIntValue("desc_extr");
String id = "http://s.weibo.com/weibo/"+URLCodeUtil.getURLEncode(name, "utf-8") + "&Refer=top"; String id = "http://s.weibo.com/weibo/"+URLCodeUtil.getURLEncode(name, "utf-8") + "&Refer=top";
WeiboHotSearch hotSearch = new WeiboHotSearch(id, name, hotCount, hot); WeiboHotSearch hotSearch = new WeiboHotSearch(id, name, hotCount, hot, rankCount);
logger.info("采集到的数据:::{}", hotSearch); logger.info("采集到的数据:::{}", hotSearch);
result.add(hotSearch); result.add(hotSearch);
} }
......
...@@ -35,6 +35,7 @@ public class WeiboHotSearchRun extends Thread{ ...@@ -35,6 +35,7 @@ public class WeiboHotSearchRun extends Thread{
doc.put("day", weiboHotSearch.getDay()); doc.put("day", weiboHotSearch.getDay());
doc.put("time", weiboHotSearch.getTime()); doc.put("time", weiboHotSearch.getTime());
doc.put("changeCount", changeCount); doc.put("changeCount", changeCount);
doc.put("rank", weiboHotSearch.getRank());
data.add(doc); data.add(doc);
} }
weiboHotSearchDAO.addWeiboHotSearch(data); weiboHotSearchDAO.addWeiboHotSearch(data);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment