如何从同一站点为这些文章设置默认选择?

时间:2011-08-16 11:55:00

标签: android jsoup

我正在尝试检索此网址的整个概述部分

我在三篇不同文章中寻找的元素是什么?

http://xbox360.gamespy.com/xbox-360/project-dark/

是否还要创建默认选择器以检索此页面的概述?

http://wii.gamespy.com/wii/ben-10-galactic-racing/

EDIT http://wwww.gamespy.com/pc/6-great-games

我想为不同的标签制作一个选择器。因此,如果一个网址被选中,如果它有选择器,那么它将加载数据,如果它没有,它将尝试另一个选择。

我怎么能这样做?

是否可以创建不同的选择器,为不同的文章寻找不同的标签?

2 个答案:

答案 0 :(得分:1)

查找div id“概述 - 部分”,然后选择p孩子。

答案 1 :(得分:1)

这应该得到所有三个网页的概述文本

// Get the overview div
Element overview = doc.select("div#object-overview").last();

// Get the paragraph element
Element paragraph = overview.select("p").last();
System.out.println(paragraph.text());

对于不同网页的不同选择器,您可以执行类似HashMap的操作。

// Create new HashMap
HashMap<String, String> selectorMap = new HashMap<String, String>();

// Put the Key-Value pair in the Hashmap
selectorMap.put("http://wii.gamespy.com/wii/ben-10-galactic-racing/", "div#object-overview");

// Get the value by supplying the key (the webpage's url)
String selector = selectorMap.get("http://wii.gamespy.com/wii/ben-10-galactic-racing/");

如果您正在寻找,请告诉我。

获取功能列表:

// Get the overview div element
Element featureList = doc.select("div.callout-box").last();

Elements features = featureList.select("li");

ListIterator<Element> featList = features.listIterator();
while (featList.hasNext()) {
    System.out.println(featList.next().text() + "\n");

}

获取版本列表:

// Get the div.columns element - this is the base of each edition
Elements editions = doc.select("div.columns");

ListIterator<Element> editionsList = editions.listIterator();
while (editionsList.hasNext()) {
    // Get that edition
    Element edition = editionsList.next();

    // Get the edition name element
    Element editionName = edition.select("h3").first();
    System.out.println(editionName.text());

    // Get the edition info element
    Element editionInfo = edition.select("p").last();
    System.out.println(editionInfo.text() + "\n");

}
相关问题