Get source of website in java

前端 未结 8 1604
轮回少年
轮回少年 2020-12-30 17:37

I would like to use java to get the source of a website (secure) and then parse that website for links that are in it. I have found how to connect to that url, but then how

8条回答
  •  无人及你
    2020-12-30 17:44

    Try using the jsoup library.

    import java.io.IOException;
    import org.jsoup.Jsoup;
    import org.jsoup.nodes.Document;
    
    
    public class ParseHTML {
    
        public static void main(String args[]) throws IOException{
            Document doc = Jsoup.connect("https://www.wikipedia.org/").get();
            String text = doc.body().text();
    
            System.out.print(text);
        }
    }
    

    You can download the jsoup library here.

提交回复
热议问题