Here you can find the source of findFirstByTag(Element element, String tag)
public static Element findFirstByTag(Element element, String tag)
//package com.java2s; /**//from www. j a v a 2 s. co m * Copyright (C) 2012-2014 Gist Labs, LLC. (http://gistlabs.com) * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ import org.jsoup.nodes.Element; import org.jsoup.select.Elements; public class Main { /** Returns the first element found with the given tag (or tag sequence separated by '/') or null. */ public static Element findFirstByTag(Element element, String tag) { return findFirstByTag(element, tag.split("/"), 0); } private static Element findFirstByTag(Element current, String[] tags, int index) { if (index < tags.length) { Elements elements = current.getElementsByTag(tags[index]); for (Element element : elements) { Element result = findFirstByTag(element, tags, index + 1); if (result != null) return result; } return null; } else return current; } }