当前位置: 首页>>代码示例>>Java>>正文


Java Node.previousSibling方法代码示例

本文整理汇总了Java中org.jsoup.nodes.Node.previousSibling方法的典型用法代码示例。如果您正苦于以下问题:Java Node.previousSibling方法的具体用法?Java Node.previousSibling怎么用?Java Node.previousSibling使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jsoup.nodes.Node的用法示例。


在下文中一共展示了Node.previousSibling方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getPreviousNonEmptyNode

import org.jsoup.nodes.Node; //导入方法依赖的package包/类
public Node getPreviousNonEmptyNode(Node input) {
    if (input == null) return null;

    Node sibling = input.previousSibling();
    if (sibling == null) return null;
    if (sibling instanceof TextNode && ((TextNode) sibling).text().replaceAll("\u00A0", " ").trim().length() == 0) {
        return getPreviousNonEmptyNode(sibling);
    }
    return sibling;
}
 
开发者ID:andyphillips404,项目名称:awplab-core,代码行数:11,代码来源:JsoupSession.java

示例2: parseObjectives

import org.jsoup.nodes.Node; //导入方法依赖的package包/类
private void parseObjectives(final Quest quest, final Element mainContainer, final Element questName) {
	// Objectives section
	Node objectivesNode = questName.nextSibling();
	
	// Objectives text is the first non-empty text node immediately following the header
	while (!(objectivesNode instanceof TextNode) || ((TextNode) objectivesNode).text().trim().isEmpty()) {
		objectivesNode = objectivesNode.nextSibling();
	}
	
	final Node beforeObjectives = objectivesNode.previousSibling();
	
	// If there is a h2.heading-size-3 right before the "objectives" text, it is probably not objectives,
	// but rather progress or completion, like on the quest "Draenei Tail"
	if (!(beforeObjectives instanceof Element && ((Element) beforeObjectives).tagName().equals("h2")
			&& ((Element) beforeObjectives).hasClass("heading-size-3"))) {
		quest.setObjectives(((TextNode) objectivesNode).text().trim());
	}
	
	// Objective completion stages
	final Elements iconlists = mainContainer.select("table.iconlist");
	final Element stagesTable = iconlists.first();
	
	if (stagesTable != null) {
		// Remove any subtables
		stagesTable.select("table.iconlist").remove();
		
		for (final Element stageLink : stagesTable.getElementsByTag("a")) {
			// Find the innermost td element enclosing the a, and add its whole text
			Element parent = stageLink.parent();
			
			while (!parent.tagName().equals("td")) {
				parent = parent.parent();
			}
			
			quest.getStages().add(parent.text());
		}

		// Suggested players
		final Element suggestedPlayers = stagesTable.getElementsContainingOwnText("Suggested players:").first();
		
		if (suggestedPlayers != null) {
			String playerCountStr =
					getRegexGroup(suggestedPlayers.ownText(), "Suggested players: ([0-9]+)", 1).get();
			quest.setGroupSize(Integer.parseInt(playerCountStr));
		}
	}
	
	// Provided items
	if (iconlists.size() >= 2) {
		final Element maybeProvided = iconlists.get(1);
		final Node before = maybeProvided.previousSibling();
		
		if (before instanceof TextNode && ((TextNode) before).text().contains("Provided")) {
			maybeProvided.select("table.iconlist").remove();
			
			for (final Element itemLink : maybeProvided.getElementsByTag("a")) {
				quest.getProvidedItems().add(itemLink.text());
			}
		}
	}
}
 
开发者ID:Maia-Everett,项目名称:questfiller,代码行数:62,代码来源:QuestParser.java


注:本文中的org.jsoup.nodes.Node.previousSibling方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。