Fork me on GitHub

jsoup 获取网页

pom.xml 中添加

 		<dependency>
		  <!-- jsoup HTML parser library @ http://jsoup.org/ -->
		  <groupId>org.jsoup</groupId>
		  <artifactId>jsoup</artifactId>
		  <version>1.10.2</version>
		</dependency>

获取网页信息

    
    import org.jsoup.Jsoup;
    import org.jsoup.nodes.Document;
    import org.jsoup.nodes.Element;
    import org.jsoup.select.Elements;
    
    String url = "需要获取的网页地址url"
    Document doc = Jsoup.connect(url).get();
    String css = "#container > div.content >div" //获取到css选择器里内容
    Elements select = doc.select(css);
    for (Element element : select) {
        String href = element.getElementsByTag("a").attr("href");
        //....
    }

>css获取:打开开发者工具(F12)->点击获取到需要的内容->鼠标右击选择copy->copy selector
>[jsoup API文档]https://jsoup.org/apidocs/overview-summary.html
>[jsoup开发指南,jsoup中文使用手册,jsoup中文文档](http://www.open-open.com/jsoup/)
posted @ 2018-10-15 10:58  一个BUG难搞啊  阅读(489)  评论(0编辑  收藏  举报