81,091
社区成员
发帖
与我相关
我的任务
分享
package caiji;
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 Jsoup01 {
public static void main(String[] args) {
String getUrl = "http://www.epzw.com/files/article/topmonthvisit/0/1.htm";
String g1 = ".grid > tbody > tr > td > strong > a";
String g2 = "abs:href";
try {
Document doc = Jsoup.connect(getUrl).timeout(60000).get();
Elements links = doc.select(g1);
for (Element link : links) {
String bookURL = link.attr(g2);
String bookTitle=link.text();
System.out.println(bookURL+" "+bookTitle);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
Elements elements = doc.select("div#content > table:eq(0) > tr:eq(0) > td:eq(0) > table:eq(0) > tr:eq(1) > td:lt(4)");
for(Element e : elements){
System.out.println(e.text());
}
Document doc = Jsoup.connect("http://example.com/").get();
Elements mapLabel = doc.select("B:matchesOwn(MPN)");
Elements a = doc.select("A:matchesOwn(Substitute)");
Elements b = doc.select("B:matchesOwn(Name)");
Element td = b.size() > 0 ? b.get(0).parent() : null;
td = td == null ? null : td.nextElementSibling();
parent.setMaterName(td == null ? "" : getText(td));
Elements tds = doc.select("td:matchesOwn(Risk_Grade)");
td = tds.size() > 0 ? tds.get(0).nextElementSibling() : null;
parent.setRiskGrade(td == null ? "" : getText(td));