How to get page meta (title, description, images) like facebook attach url using Regex in java

前端 未结 4 1631
孤城傲影
孤城傲影 2021-02-19 08:35

How to get page meta (title, description, images) like facebook attach url using Regex in .java

4条回答
  •  情歌与酒
    2021-02-19 09:08

    As Ishikawa Yoshi mentioned, use JSoup

    Example:

    Document doc = Jsoup.connect("http://example.com/").get()
    for(Element meta : doc.select("meta")) {
        System.out.println("Name: " + meta.attr("name") + " - Content: " + meta.attr("content"));
    }
    

    This code is untested, hope this helps.

    Using RegEx for scraping a document is a bad idea, read about it on Coding Horror

提交回复
热议问题