1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
|
private Logger log = LoggerFactory.getLogger(FollowStartIndex.class); public void startIndex() { while (true) { Avaiuk avaiuk = Avaiuk.dao.findFirst("select * from avaiuk where flag=0 limit 1"); avaiuk.set("flag", 1).update(); getFllow(avaiuk.getLong("uk"), 0); } }
static String url = "http://yun.baidu.com/pcloud/friend/getfollowlist?query_uk=%s&limit=24&start=%s&bdstoken=e6f1efec456b92778e70c55ba5d81c3d&channel=chunlei&clienttype=0&web=1&logid=MTQ3NDA3NDg5NzU4NDAuMzQxNDQyMDY2MjA5NDA4NjU="; static Map map = new HashMap();
static { map.put("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36"); map.put("X-Requested-With", "XMLHttpRequest"); map.put("Accept", "application/json, text/javascript, */*; q=0.01"); map.put("Referer", "https://yun.baidu.com/share/home?uk=325913312#category/type=0"); map.put("Accept-Language", "zh-CN"); }
public void getFllow(long uk, int start, boolean index) { log.info("进来getFllow,uk:{},start:{}", uk, start); boolean exitUK = false; try { exitUK = Redis.use().exists(uk); } catch (Exception e) { exitUK = true; } if (!exitUK) { Redis.use().set(uk, ""); if (index) { indexResource(uk); } recFollow(uk,start,true); } else { if (start > 0) { recFollow(uk,start,false); } else { log.warn("uk is index:{}", uk); } } } public void recFollow(long uk,int start,boolean goPage){ try { Thread.sleep(4000); } catch (InterruptedException e) { e.printStackTrace(); } String real_url = String.format(url, uk, start); ResponseBody body = OkhttpUtil.syncGet(real_url, Headers.of(map)); if (body != null) { try { Follow follow = JSON.parseObject(body.string(), Follow.class); if (follow.getErrno() == 0) { List<Follow.FollowListBean> followListBeen = follow.getFollow_list(); if (followListBeen != null && followListBeen.size() > 0) { log.info("不为空:{}", follow); for (Follow.FollowListBean bean : followListBeen) { int follow_count = bean.getFollow_count(); int shareCount=bean.getPubshare_count(); if (follow_count > 0) { if (shareCount > 0) { getFllow(bean.getFollow_uk(), 0, true); } else { getFllow(bean.getFollow_uk(), 0, false); } } } if(goPage){ int total_count = follow.getTotal_count(); int total_page = (total_count - 1) / 24 + 1; for (int i = 1; i < total_page; i++) { getFllow(uk, i * 24,false); } } } else { log.info("为空:{}", follow); } } } catch (IOException e) { e.printStackTrace(); } } }
long uinfoId = 0; long nullStart = System.currentTimeMillis();
public void indexResource(long uk) { while (true) { String url = "http://pan.baidu.com/wap/share/home?uk=%s&start=%s&adapt=pc&fr=ftw"; String real_url = String.format(url, uk, 0);
YunData yunData = DataUtil.getData(real_url);
if (yunData != null) { log.info("{}", yunData.toString()); int share_count = yunData.getUinfo().getPubshare_count(); if (share_count > 0) { Uinfo uinfo = new Uinfo(); uinfo.set("uname", yunData.getUinfo().getUname()).set("avatar_url", yunData.getUinfo().getAvatar_url()).set("uk", uk).set("incache", 1).save(); uinfoId = uinfo.getLong("id"); List<Records> recordses = yunData.getFeedata().getRecords(); for (Records record : recordses) { new ShareData().set("title", record.getTitle()).set("shareid", record.getShareid()).set("uinfo_id", uinfoId).save(); }
} int totalPage = (share_count - 1) / 20 + 1;
int start = 0; if (totalPage > 1) { for (int i = 1; i < totalPage; i++) { start = i * 20; real_url = String.format(url, uk, start); yunData = DataUtil.getData(real_url); if (yunData != null) { log.info("{}", yunData.toString()); List<Records> recordses = yunData.getFeedata().getRecords(); for (Records record : recordses) { new ShareData().set("title", record.getTitle()).set("shareid", record.getShareid()).set("uinfo_id", uinfoId).save(); } } else { i--; log.warn("uk:{},msg:{}", uk, yunData); long temp = nullStart; nullStart = System.currentTimeMillis(); if ((nullStart - temp) < 1500) { try { Thread.sleep(60000); } catch (InterruptedException e) { e.printStackTrace(); } }
}
}
} break; } else { log.warn("uk:{},msg:{}", uk, yunData); long temp = nullStart; nullStart = System.currentTimeMillis(); if ((nullStart - temp) < 1500) { try { Thread.sleep(60000); } catch (InterruptedException e) { e.printStackTrace(); } } } }
}
|