Here you can find the source of getContainersForLink(Document document, String link)
public static List<Element> getContainersForLink(Document document, String link)
//package com.java2s; //License from project: Open Source License import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import java.util.ArrayList; import java.util.List; public class Main { public static List<Element> getContainersForLink(Document document, String link) { List<Element> elements = new ArrayList<>(); for (Element element : document.body().getAllElements()) { if (containsLink(element, link)) elements.add(element);/*from w ww . j av a2 s .c o m*/ } return elements; } public static boolean containsLink(Element element, String link) { int links = 0; for (Element child : element.children()) { if (child.tagName().equals("a") && child.hasAttr("href") && child.attr("href").contains(link)) links++; } return links > 0; } }