List of utility methods to do HTML Jsoup Element
ArrayList | convertLinksToStrings(Elements links) convert Links To Strings ArrayList<String> result = new ArrayList<String>(); for (Element link : links) { result.add(link.attr("abs:href")); return result; |
String | convertNodeToText(Element element) convert Node To Text if (element == null) return ""; final StringBuilder buffer = new StringBuilder(); new NodeTraversor(new NodeVisitor() { @Override public void head(Node node, int depth) { if (node instanceof TextNode) { TextNode textNode = (TextNode) node; ... |
void | convertTablesToDivs(Element body) convert Tables To Divs Elements elements = body.select("table"); for (Element element : elements) { element.tagName("div"); elements = body.select("tbody"); for (Element element : elements) { element.tagName("div"); elements = body.select("tr"); for (Element element : elements) { element.tagName("div"); elements = body.select("th"); for (Element element : elements) { element.tagName("p"); elements = body.select("td"); for (Element element : elements) { element.tagName("p"); |
Element | copy(Element e) copy Element res = new Element(Tag.valueOf(e.tagName()), e.baseUri()); for (Attribute a : e.attributes()) { res.attr(a.getKey(), a.getValue()); res.html(e.html()); return res; |
int | countElements(Node parent) count Elements int count = 0; List<Node> childNodes = parent.childNodes(); for (Node childNode : childNodes) { if (childNode instanceof Element) { count++; count += countElements(childNode); return count; |
Element | createSafeElement(Element sourceEl) create Safe Element String sourceTag = sourceEl.tagName(); Attributes destAttrs = new Attributes(); Element dest = new Element(Tag.valueOf(sourceTag), sourceEl.baseUri(), destAttrs); Attributes sourceAttrs = sourceEl.attributes(); for (Attribute sourceAttr : sourceAttrs) { destAttrs.put(sourceAttr); return dest; ... |
List | elementsToList(Elements elements) elements To List List<String> elementsList = new ArrayList<String>(); for (Element element : elements) { elementsList.add(element.toString()); return elementsList; |
String | extractTextWithNewlines(Element elem) Extracts text from Element, replacing with newline. elem.select("br").html(LINE_SEPARATOR); return elem.text().replace(LINE_SEPARATOR, "\n"); |
void | filterElementsByTag(List filter Elements By Tag if (tagSet.contains(element.tag().getName().toLowerCase())) results.add(element); for (Element child : element.children()) filterElementsByTag(results, child, tagSet); |
Elements | findAElementsWithId(Elements elements, String id) find A Elements With Id StringBuilder query = new StringBuilder(); query.append("a[id="); query.append(id); query.append("]"); Elements found = elements.select(query.toString()); return found; |