@Action("baiduCheck")
public String baiduCheck() throws Exception{ Doc doc = docService.get(Long.valueOf(getId())); IncludeCheck check = includeCheckService.getByDocId(Long.valueOf(getId())); if(doc != null ){ if(StringUtils.isEmpty(doc.url())){ saveOrUpdateIncludeCheck(check, Flag.FALSE.getValue(), doc); } } try { String url = doc.url(); url = URLEncoder.encode(url, "gbk"); URL u = new URL("http://www./s?wd=" + url ); URLConnection conn = u.openConnection(); BufferedReader reader = new BufferedReader(new InputStreamReader( conn.getInputStream(), "gbk")); String str = reader.readLine(); StringBuffer sb = new StringBuffer(); while (str != null) { sb.append(str); str = reader.readLine(); } String content =sb.toString(); int index = content.lastIndexOf("百度快照"); if(index !=-1){ System.out.println("找到结果啦! " +index +" docId: "+ doc.getId()); //写入检测 记录库 saveOrUpdateIncludeCheck(check, Flag.TRUE.getValue(), doc); }else{ saveOrUpdateIncludeCheck(check, Flag.FALSE.getValue(), doc); System.out.println("没有结果! " +index +" docId: "+ doc.getId()); } content=null; reader.close(); } catch (Exception e) { } redirectIndex(); return SHOW_MSG_PAGE; } /*url = URLEncoder.encode(url, "gbk");
URL u = new URL("http://www./s?wd=" + url ); URLConnection conn = u.openConnection(); BufferedReader reader = new BufferedReader(new InputStreamReader( conn.getInputStream(), "gbk")); String str = reader.readLine(); StringBuffer sb = new StringBuffer(); while (str != null) { sb.append(str); str = reader.readLine(); } String content =sb.toString(); int index = content.lastIndexOf("百度快照"); if(index !=-1){ System.out.println("找到结果啦! " +index +" docId: "+ doc.getId()); //写入检测 记录库 saveOrUpdateIncludeCheck(check, Flag.TRUE.getValue(), doc); }else{ saveOrUpdateIncludeCheck(check, Flag.FALSE.getValue(), doc); System.out.println("没有结果! " +index +" docId: "+ doc.getId()); } content=null; reader.close(); */ |
|