jsoup

1 简介
jsoup 是一款 Java 的HTML 解析器,可直接解析某个URL地址、HTML文本内容。

比起之前用的HTMLParser方便很多,而且更轻便。

语法类似jquery

2 官网地址
http://jsoup.org/

3 pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<groupId>com.snda</groupId>
	<artifactId>jsoup</artifactId>
	<version>0.1</version>
	<packaging>jar</packaging>

	<name>jsoup</name>
	<url>http://maven.apache.org</url>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.jsoup</groupId>
			<artifactId>jsoup</artifactId>
			<version>1.4.1</version>
		</dependency>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.8.2</version>
		</dependency>
	</dependencies>
</project>


4 hello world
package com.snda.jsoup;

import junit.framework.Assert;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;

public class Test {

	@org.junit.Test
	public void testGetElementById() {
		String hello = "hello jsoup";
		String html = "<html><head><title>First parse</title></head>"
				+ "<body><p>Parsed HTML into a doc.</p>" + "<div id='jsoup'>"
				+ hello + "</div>" + "</body></html>";
		Document doc = Jsoup.parse(html);
		Element content = doc.getElementById("jsoup");
		Assert.assertEquals(hello, content.text());
	}
}

你可能感兴趣的:(java,html,jquery,maven,JUnit)