Jsoup框架相对于简单,该框架封装了许多操作网页、css的方法
package HW0811;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
public class JsoupPC {
public static void main(String[] args) throws Exception{
Document doc = Jsoup.connect("https://www.oneplus.com").get();
System.out.println(doc.title());
// 用css选择器读取a标签
Elements elements = doc.select("a");
for(Element e:elements){
// 遍历href属性
String href = e.attr("href");
System.out.println(href);
}
}
}