1. 某p2p网站每天发新标,对于一个标最后投标导致标满的用户,系统会奖励38元红包,所以写啦个爬虫每隔1分钟去爬取合适的标,然后短信提醒
2. 两个要爬取的页面
============投资列表=====================
======标的详情页面如下==============
=============================
3.核心代码逻辑
public Document getDocument (String url){ try { return Jsoup.connect(url).get(); } catch (Exception e) { e.printStackTrace(); } return null; }
//1.首页抓取未完成的标 CrawUtil ft = new CrawUtil(); Document fDoc = ft.getDocument("http://www.qtyd.com/"); Elements elements=fDoc.select("dd.invset-item"); if(elements.size()<=7){ //标的列表低于7个标 return ; } try { //2.循环判断每个标的情况 for(int i=0;i<=7;i++){ //获取进度 Element elements1=elements.get(i); Elements speed=elements1.select(".item-speed"); Elements speedLine=speed.select(".invest-speed-line"); String iSpeedLine= speedLine.toString(); String speedStr = iSpeedLine.substring(iSpeedLine.lastIndexOf(":")+1,iSpeedLine.lastIndexOf("%")).trim(); //过滤掉满标的 if(Double.parseDouble(speedStr)==100.00){ continue; } //获取收益 String itemApr=elements1.select(".item-apr").text(); // if("12.00%".equals(itemApr.toString())){ // continue; // } //3.获取天数 String itemTime=elements1.select(".item-time").text(); itemTime=itemTime.replace("天","").trim(); // if(Integer.parseInt(itemTime)>50){ // continue; // } //获取标id String itemName=elements1.select(".item-name").toString(); itemName=itemName.substring(itemName.lastIndexOf("invest/")+7,itemName.lastIndexOf(".html")); CrawUtil t = new CrawUtil(); String url=String.format("http://www.qtyd.com/invest/%s.html",Integer.parseInt(itemName)); Document doc = t.getDocument(url); // 获取目标HTML代码 Elements ele1 = doc.select(".ft30"); StringBuffer stringBuffer=new StringBuffer(); stringBuffer.append("监控到有标可以投资:"); // 可投金额 String money = ele1.get(0).text().replace(",",""); // if(Double.parseDouble(money)>50000){ // continue; // } stringBuffer.append("可投金额:" + money); // 年利率 String rank = ele1.get(1).text(); stringBuffer.append("年利率:" + rank); // days String days = ele1.get(2).text(); stringBuffer.append("收益期限" + days + "天"+"\n"); stringBuffer.append("请访问:"+url+"\n"); System.out.print(stringBuffer.toString()); //发短信通知 //SmsUtil.sendSms(stringBuffer.toString(),"18758160314"); } } catch (Exception e) { e.printStackTrace(); }
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/chichengit/article/details/47170487