0
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 做过这个。请指教。

4

1 回答 1

1

获得相关的 td 标签后,您可以使用以下命令检索图像 src:
td.getElementsByTag("img").get(0).attr("src")

如果您想要包括网站名称在内的整个路径,请改用以下内容: td.getElementsByTag("img").get(0).absUrl("src")

于 2013-03-05T19:37:42.440 回答