當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。