java实现获取网站的keywords,description
获取网站的<meta name="keywords" content="" />和<meta name="description" content="“>关键字和描述内容
实现HTML解析器jsoup
下载jsoup的lib地址:http://jsoup.org/download
package cn.evan.util;
import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
public class SemanticCrawl {
public static void main(String[] args) {
Document doc = null;
try {
doc = Jsoup.connect("网址").get();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String title = doc.title();
Elements metas = doc.head().select("meta");
for (Element meta : metas) {
String content = meta.attr("content");
if ("keywords".equalsIgnoreCase(meta.attr("name"))) {
System.out.println("关键字:"+content);
}
if ("description".equalsIgnoreCase(meta.attr("name"))) {
System.out.println("网站内容描述:"+content);
}
}
Elements keywords = doc.getElementsByTag("meta");
System.out.println("标题"+title);
}
}
以上所述就是本文分享的全部内容了,希望大家能够喜欢。