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
中,因此我无法获取文本值。代码已被编辑。 .getElementsByTag是否返回一个字符串值???我从来没有为JSoup做过这个。请指教。
答案 0 :(得分:1)
如果您有问题的td标签,您可以使用以下内容来检索图像src:
td.getElementsByTag("img").get(0).attr("src")
如果您想要包含网站名称在内的整个路径,请使用以下代码:
td.getElementsByTag("img").get(0).absUrl("src")