Jsoup解析
先看一下我们要解析的:
在这里我们要找到相应的节点:
private void parseHtml() {
new Thread(){
public void run() {
try {
Document parse = Jsoup.parse(new URL("http://www.cnbeta.com/topics/444.htm"),5000);
Elements Eleclass = parse.getElementsByClass("title");
Elements Elenewsinfo = parse.getElementsByClass("newsinfo");
Elements Elepic = parse.getElementsByClass("pic");
int size = Eleclass.size();
for (int i = 0; i < size; i++) {
//头部标题
String title = Eleclass.get(i).getElementsByTag("a").text();
//获取到超链接
String href = Eleclass.get(i).getElementsByTag("a").attr("href");
//图片信息
String newsinfo = Elenewsinfo.get(i).getElementsByTag("p").text();
//图片信息
String pic = Elepic.get(i).getElementsByTag("img ").attr("src");
list.add(new Info(title, newsinfo, pic, href));
}
for (Info info : list) {
Log.i(TAG, info.toString());
}
handler.sendEmptyMessage(0);
} catch (IOException e) {
e.printStackTrace();
}
};
}.start();
}
差不多就这样了,大家自己试试看吧! 小编有点忙,以后再详细介绍。