Document doc = Jsoup.connect("http://www.stockexchangeofmauritius.com/officialquotes/").get();
Element table = doc.select("table").get(0);
Elements trs = table.select("tr");
Iterator trIter = trs.iterator();
boolean firstRow = true;
trIter.next();
stmtt = conn1.createStatement();
if (count < 1) {
while (trIter.hasNext()) {
Element tr = (Element) trIter.next();
if (firstRow) {
firstRow = false;
continue;
}
Elements tds = tr.select("td");
Iterator tdIter = tds.iterator();
int tdCount = 1;
String symbol = null;
String trend = null;
String nominal = null;
while (tdIter.hasNext()) {
Element td = (Element) tdIter.next();
switch (tdCount++) {
case 1:
symbol = String.valueOf(td.text());
break;
case 2:
trend = td.getElementsByTag("img").get(0).absUrl("src");
break;
case 3:
nominal = String.valueOf(td.text());
break;
该img
标签位于td
表格的 a 中,因此我无法获取文本值。代码已被编辑。.getElementsByTag 是否返回字符串值???我从来没有为 JSoup 做过这个。请指教。