需要一个包: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:///
public static void getWuMaoW() {
String url = "http:///";
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();
}
}
}