分享

百度网页收录---暂存

 闪宁斯达 2010-09-01
 
@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(); */

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多