日期:2014-05-16  浏览次数:20338 次

基于Jsoup获取页面的header map,title和keywords

需求:

需要采集页面的title和keyword

实现:

依赖:

<dependency>
	<groupId>org.jsoup</groupId>
	<artifactId>jsoup</artifactId>
	<version>1.6.3</version>
</dependency>

代码:

Connection.Response response = connection.execute();
Map<String, String> headerMap= response.headers();
String body = response.body();
Document document = Jsoup.parse(body);
String title = document.head().select("title").text();
String keywords = document.head().select("meta[name=keywords]").attr("content");

?