Full Link Extraction using java

后端 未结 2 2023
感情败类
感情败类 2021-01-16 04:45

My goal is to always get the same string (which is the URI in my case) while reading the href property from a link. Example: Suppose think that a html file it have somany li

2条回答
  •  旧时难觅i
    2021-01-16 05:15

    Use the URL object:

    URL url = new URL(URL context, String spec)

    Here's an example:

    import java.net.*;

    public class Test {
    public static void main(String[] args) throws Exception {
       URL base = new URL("http://www.java.com/dit/index.html");   
       URL url = new URL(base, "../hello.html");
    
       System.out.println(base);
       System.out.println(url);
    }
    }
    

    It will print:

    http://www.java.com/dit/index.html
    http://www.java.com/hello.html
    

提交回复
热议问题