Jsoup解析html

2020-11-09 10:03:26 浏览数 (2)

代码语言:javascript复制
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class Test {
	public static void main(String args[])throws Exception{
		String index="";
		Document doc = Jsoup.connect("http://www.baidu.com").get();
		//System.out.println(doc.getElementsMatchingText("搜索设置"));
		//
		//System.out.println(doc.attr("href"));//得到属性的值
		System.out.println(doc.title());
		Elements title = doc.select("title");
		for (Element el : title) {
			index=el.text();
		}
		System.out.println(index);
	}
}

0 人点赞