jsp获取某网站所有链接地址

<%@ page contentType="text/html; charset=gb2312" language="java"
    import="java.util.regex.*" errorPage=""%>
<%
    String sCurrentLine;
    String sTotalString;
    sCurrentLine = "";
    sTotalString = "";
    java.io.InputStream l_urlStream;
    java.net.URL l_url = new java.net.URL("http://www.baidu.com");
    java.net.HttpURLConnection l_connection = (java.net.HttpURLConnection) l_url
            .openConnection();
    l_connection.connect();
    l_urlStream = l_connection.getInputStream();
    java.io.BufferedReader l_reader = new java.io.BufferedReader(
            new java.io.InputStreamReader(l_urlStream));

    while ((sCurrentLine = l_reader.readLine()) != null) {
        sTotalString += sCurrentLine;
    }
    //String regEx = "href=([^/"']*)>";
    String regEx = "href=/"([^/"]*)/"";//找出href="****"的链接
    Pattern p = Pattern.compile(regEx, Pattern.CASE_INSENSITIVE);
    Matcher m = p.matcher(sTotalString);
    int j = 0;
    while (m.find()) {
        j++;
        out.println("m.group(" + j + "): " + m.group(0) + "<br>");
    }
    regEx = "href='([^']*)'";//找出href='****'的链接
    p = Pattern.compile(regEx, Pattern.CASE_INSENSITIVE);//Pattern.CASE_INSENSITIVE查找忽略大小写
    m = p.matcher(sTotalString);
    while (m.find()) {
        j++;
        out.println("m.group(" + j + "): " + m.group(0) + "<br>");
    }
   

%>
 
阅读更多
上一篇jre1.5以上applet数字签名方法
下一篇display Tab 中列名显示中文
想对作者说点什么? 我来说一句

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

关闭
关闭