获得网页信息 并获取相应值

  public String getno(String url1){
     String CurrentLine="";
         String TotalString="";
         InputStream urlStream;
         String content = null;
         String replaceStr=null;
         try {
             URL url = new URL(url1);
             HttpURLConnection connection = (HttpURLConnection)url.openConnection();
             connection.connect();
             urlStream = connection.getInputStream();
             BufferedReader reader = new BufferedReader(
             new InputStreamReader(urlStream,"gbk"));
             while ((CurrentLine = reader.readLine()) != null) {
             TotalString += CurrentLine+" ";
                  }
             content =  TotalString;
             System.out.println(content);
            
             //String str = "&ch=1005&kind=941,2323,8097&row=20&kind=2&table=1&author=1&kind=<url >";
             CharSequence inputStr = content.subSequence(0, content.length());
             String patternStr = "&cardno=([^&]+)";

//              Compile regular expression
             Pattern pattern = Pattern.compile(patternStr);
             Matcher matcher = pattern.matcher(inputStr);
             while (matcher.find()) {
//              Get the match result
              replaceStr= matcher.group();
             replaceStr = replaceStr.replaceAll(patternStr,"$1");
             System.out.println(replaceStr);
             }
         } catch (Exception e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
         }
   return replaceStr;
    } 

阅读更多
想对作者说点什么? 我来说一句

HttpGetWebInfo

2017年11月06日 7KB 下载

获取网页信息的小工具

2013年08月01日 11KB 下载

没有更多推荐了,返回首页

不良信息举报

获得网页信息 并获取相应值

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭