java使用jsoup解析網站TDK,獲取title、keywords、description
阿新 • • 發佈:2018-12-26
/**
* java使用jsoup解析網站TDK,獲取title、keywords、description
* @author www.wuliaokankan.cn
*
*/
public class WebTDKUtil {
public static void main(String[] args) {
Document doc = null;
try {
doc = Jsoup.connect("https://www.wuliaokankan.cn").get();
} catch (IOException e) {
e.printStackTrace();
}
String title = doc.title();
String keywords ="";
String description="";
Elements metas = doc.head().select("meta");
for (Element meta : metas) {
String content = meta.attr("content");
if ("keywords".equalsIgnoreCase(meta.attr("name"))) {
keywords = content;
}
if ("description".equalsIgnoreCase(meta.attr("name"))) {
description = content;
}
}
System.out.println("標題:" + title);
System.out.println("網站內容描述:" + description);
System.out.println("關鍵字:" + keywords);
}
* java使用jsoup解析網站TDK,獲取title、keywords、description
* @author www.wuliaokankan.cn
*
*/
public class WebTDKUtil {
public static void main(String[] args) {
Document doc = null;
try {
doc = Jsoup.connect("https://www.wuliaokankan.cn").get();
} catch (IOException e) {
}
String title = doc.title();
String keywords ="";
String description="";
Elements metas = doc.head().select("meta");
for (Element meta : metas) {
String content = meta.attr("content");
if ("keywords".equalsIgnoreCase(meta.attr("name"))) {
keywords = content;
if ("description".equalsIgnoreCase(meta.attr("name"))) {
description = content;
}
}
System.out.println("標題:" + title);
System.out.println("網站內容描述:" + description);
System.out.println("關鍵字:" + keywords);
}
}
無聊原創,轉載請註明出處!