@SuppressWarnings("unchecked") private <T extends Node> List<T> list(final NodeList list) throws ParserException { final List<T> filtered = new ArrayList<>(); final NodeIterator iterator = list.elements(); while (iterator.hasMoreNodes()) { filtered.add((T) iterator.nextNode()); } return filtered; }
public List<String> extractLinks(PageData pageData) { NodeList nodes = pageData.getNodes(); if (nodes == null) { return Collections.emptyList(); } NodeList linkNodes = nodes.extractAllNodesThatMatch(nodeFilter, true); ArrayList<String> links = new ArrayList<String>(linkNodes.size()); SimpleNodeIterator it = linkNodes.elements(); while (it.hasMoreNodes()) { Tag tag = (Tag) it.nextNode(); String href = new String(tag.getAttribute("href")); href = href.trim().replaceAll("&", "&"); links.add(href); } return links; }
/** * Gets a frame by name. * Names are checked without case sensitivity and conversion to uppercase * is performed with the locale provided. * @param name The name of the frame to retrieve. * @param locale The locale to use when converting to uppercase. * @return The specified frame or <code>null</code> if it wasn't found. */ public FrameTag getFrame (String name, Locale locale) { Node node; FrameTag ret; ret = null; name = name.toUpperCase (locale); for (SimpleNodeIterator e = getFrames ().elements (); e.hasMoreNodes () && (null == ret); ) { node = e.nextNode(); if (node instanceof FrameTag) { ret = (FrameTag)node; if (!ret.getFrameName ().toUpperCase (locale).equals (name)) ret = null; } } return (ret); }
SimpleNodeIterator it = list.elements(); while (it.hasMoreNodes()) { Node node = it.nextNode();
/** * Gets a frame by name. * Names are checked without case sensitivity and conversion to uppercase * is performed with the locale provided. * @param name The name of the frame to retrieve. * @param locale The locale to use when converting to uppercase. * @return The specified frame or <code>null</code> if it wasn't found. */ public FrameTag getFrame (String name, Locale locale) { Node node; FrameTag ret; ret = null; name = name.toUpperCase (locale); for (SimpleNodeIterator e = getFrames ().elements (); e.hasMoreNodes () && (null == ret); ) { node = e.nextNode(); if (node instanceof FrameTag) { ret = (FrameTag)node; if (!ret.getFrameName ().toUpperCase (locale).equals (name)) ret = null; } } return (ret); }
SimpleNodeIterator it = list.elements(); while (it.hasMoreNodes()) { Node node = it.nextNode();
/** * @see org.htmlparser.nodes.TagNode#accept(org.htmlparser.visitors.NodeVisitor) */ public void accept(NodeVisitor visitor) { // be invisible but show the children (if they like visits) NodeList children = m_decorated.getChildren(); if (children == null) { return; } SimpleNodeIterator itChildren = children.elements(); while (itChildren.hasMoreNodes()) { itChildren.nextNode().accept(visitor); } }
/** * Find the textarea tag matching the given name * @param name Name of the textarea tag to be found within the form. * @return The <code>TEXTAREA</code> tag with the matching name. */ public TextareaTag getTextAreaTag(String name) { TextareaTag textareaTag=null; boolean found = false; for (SimpleNodeIterator e=getFormTextareas ().elements();e.hasMoreNodes() && !found;) { textareaTag = (TextareaTag)e.nextNode(); String textAreaName = textareaTag.getAttribute("NAME"); if (textAreaName!=null && textAreaName.equals(name)) found = true; } if (found) return (textareaTag); else return (null); }
/** * Extracts the title from the given HTML. * * @return never null, just an empty string if not parsable. */ public static String extractTitle(String html) throws ParserException { String title = ""; Parser parser = new Parser(html); NodeList matches = parser.extractAllNodesThatMatch(TITLE_FILTER); SimpleNodeIterator it = matches.elements(); while (it.hasMoreNodes()) { TitleTag node = (TitleTag) it.nextNode(); title = node.getTitle().trim(); } return title; }
/** * Find the textarea tag matching the given name * @param name Name of the textarea tag to be found within the form. * @return The <code>TEXTAREA</code> tag with the matching name. */ public TextareaTag getTextAreaTag(String name) { TextareaTag textareaTag=null; boolean found = false; for (SimpleNodeIterator e=getFormTextareas ().elements();e.hasMoreNodes() && !found;) { textareaTag = (TextareaTag)e.nextNode(); String textAreaName = textareaTag.getAttribute("NAME"); if (textAreaName!=null && textAreaName.equals(name)) found = true; } if (found) return (textareaTag); else return (null); }
/** * @see org.htmlparser.Tag#accept(org.htmlparser.visitors.NodeVisitor) */ public void accept(NodeVisitor visitor) { // be invisible but show the children (if they like visits) NodeList children = m_decorated.getChildren(); if (children == null) { return; } SimpleNodeIterator itChildren = children.elements(); while (itChildren.hasMoreNodes()) { itChildren.nextNode().accept(visitor); } }
/** * Get the input tag in the form corresponding to the given name * @param name The name of the input tag to be retrieved * @return Tag The input tag corresponding to the name provided */ public InputTag getInputTag (String name) { InputTag inputTag; boolean found; String inputTagName; inputTag = null; found = false; for (SimpleNodeIterator e = getFormInputs().elements();e.hasMoreNodes() && !found;) { inputTag = (InputTag)e.nextNode(); inputTagName = inputTag.getAttribute("NAME"); if (inputTagName!=null && inputTagName.equalsIgnoreCase(name)) found=true; } if (found) return (inputTag); else return (null); }
/** * Get the input tag in the form corresponding to the given name * @param name The name of the input tag to be retrieved * @return Tag The input tag corresponding to the name provided */ public InputTag getInputTag (String name) { InputTag inputTag; boolean found; String inputTagName; inputTag = null; found = false; for (SimpleNodeIterator e = getFormInputs().elements();e.hasMoreNodes() && !found;) { inputTag = (InputTag)e.nextNode(); inputTagName = inputTag.getAttribute("NAME"); if (inputTagName!=null && inputTagName.equalsIgnoreCase(name)) found=true; } if (found) return (inputTag); else return (null); }
/** * @see org.htmlparser.Tag#accept(org.htmlparser.visitors.NodeVisitor) */ public void accept(NodeVisitor visitor) { // be invisible but show the children (if they like visits) NodeList children = m_decorated.getChildren(); if (children == null) { return; } SimpleNodeIterator itChildren = children.elements(); while (itChildren.hasMoreNodes()) { itChildren.nextNode().accept(visitor); } }
int defaultSize = 22; try { for (NodeIterator e = list.elements(); e.hasMoreNodes(); ) { Node node = e.nextNode(); StringBuilder _sbBuilder = null;
/** * Set the children of this node. * @param children The new list of children this node contains. */ /* See bug: https://sourceforge.net/tracker/?func=detail&aid=1755537&group_id=24399&atid=381399 * A check needs to be performed to see that a tag cannot be its own parent * or child and if it is the case then just ignore it */ public void setChildren (NodeList children) { /* Always Initialize the children field as in the constructor its being * initialized to null */ this.children = new NodeList(); /* Do nothing if the children node list contains the node * (i.e. the node whose children is being set) itself */ for(SimpleNodeIterator it = children.elements(); it.hasMoreNodes();){ Node nodetoadd = it.nextNode(); if(this != nodetoadd){ this.children.add(nodetoadd); } } //this.children = children; }