使用 JSoup 获取一些属性

Get Some Attributes with JSoup

我在进行一些编程练习,但我在这部分卡住了(也是因为我缺乏网络编程知识):我要从这个页面获取一些信息:http://db.fowtcg.us/index.php?p=card&code=VS01-003+R,但仅卡片属性,我在使用 JSoup 时遇到了一些困难,我能够通过以下方式获取数据:

        Document doc = Jsoup.connect("http://db.fowtcg.us/?p=card&code=TTW-080+SR").get();
        Elements newsHeadlines = doc.select("div.card-props");
        System.out.println(newsHeadlines);

但是我无法从 Element 对象取回数据(但我可以看到它在那里调试)。

我怎样才能获取这些信息?

在这里,改用这个:

Elements property = doc.select("div.col-xs-12.col-sm-7.box.card-props");

您需要确保您使用的 selector 与原始 html 文档完全匹配。

您也可以使用 contains/ends-with 选择器

//contains
Elements property = doc.select("div[class*=card-props]");

//ends-with
Elements property = doc.select("div[class$=card-props]");

通过下面 link 了解更多关于 css 选择器的信息。

http://jsoup.org/cookbook/extracting-data/selector-syntax