0
点赞
收藏
分享

微信扫一扫

java爬虫(Jsoup)爬取某新闻站点标题

转角一扇门 2022-04-02 阅读 62
jsoupjavajar


需要一个包:jsoup-1.7.3.jar​ 

有一定的java和js基础

package wang.test;

import java.io.IOException;

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

public class JsoupTestTitle {
public static void main(String[] args) throws Exception {
getWuMaoW();
}

// 获取http://www.ltaaa.com/
public static void getWuMaoW() {
String url = "http://www.ltaaa.com/";
Document doc = null;
try {
doc = Jsoup.connect(url).get();
Elements listDiv = doc.getElementsByAttributeValue("class", "show");
for (Element element : listDiv) {
Elements texts = element.getElementsByTag("a");
for (Element text : texts) {

// 取所有文本
// String ptext = text.text();

String ptext = text.attr("title");
System.out.println("标题:" + ptext);

}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

}

 java爬虫(Jsoup)爬取某新闻站点标题_java



举报

相关推荐

0 条评论