簡體   English   中英

從HTML獲取favicon(JSOUP)

[英]get favicon from html (JSOUP)

如何從html字符串中獲取圖標路徑使用JSOUP?

我找到了在網頁上添加favicon的不同方式 -

(在谷歌)

我可以使用的第一種方法使用doc.select(“ html head meta”)

但我無法選擇鏈接標簽

獲取head元素的文件名:

Connection con2=Jsoup.connect(url);
Document doc = con2.get();
Element e=doc.head().select("link[href~=.*\\.ico]").first();
String url=e.attr("href");

http://jsoup.org/cookbook/extracting-data/attributes-text-html

http://jsoup.org/cookbook/extracting-data/selector-syntax

正如Uwe Plonus在評論中指出的那樣,你總是可以從<website>/favicon.ico獲得favicon

Google favicon

提交答案已經很晚了,但檢查的正確方法是“rel”標簽

 public boolean checkFevicon() {
        Elements e = doc.head().select("link[rel=shortcut icon]");
        if (e.isEmpty()) {
            return false;
        } else {
            return true;
        }
    }

相當於jQuery

  $("link[rel='shortcut icon']")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM