org.jsoup.select.NodeVisitor Java Examples
The following examples show how to use
org.jsoup.select.NodeVisitor.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Node.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Perform a depth-first traversal through this node and its descendants. * @param nodeVisitor the visitor callbacks to perform on each node * @return this node, for chaining */ public Node traverse(NodeVisitor nodeVisitor) { Validate.notNull(nodeVisitor); NodeTraversor traversor = new NodeTraversor(nodeVisitor); traversor.traverse(this); return this; }
Example #2
Source File: Node.java From jsoup-learning with MIT License | 5 votes |
/** * Perform a depth-first traversal through this node and its descendants. * @param nodeVisitor the visitor callbacks to perform on each node * @return this node, for chaining */ public Node traverse(NodeVisitor nodeVisitor) { Validate.notNull(nodeVisitor); NodeTraversor traversor = new NodeTraversor(nodeVisitor); traversor.traverse(this); return this; }
Example #3
Source File: QAKIS.java From NLIWOD with GNU Affero General Public License v3.0 | 4 votes |
public void search(IQuestion question, String language) throws Exception { String questionString; if (!question.getLanguageToQuestion().containsKey(language)) { return; } questionString = question.getLanguageToQuestion().get(language); log.debug(this.getClass().getSimpleName() + ": " + questionString); final HashSet<String> resultSet = new HashSet<String>(); String url = "http://qakis.org/qakis/index.xhtml"; RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(this.timeout).build(); HttpClient client = HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).build(); HttpPost httppost = new HttpPost(url); HttpResponse ping = client.execute(httppost); //Test if error occured if(ping.getStatusLine().getStatusCode()>=400){ throw new Exception("QAKIS Server could not answer due to: "+ping.getStatusLine()); } Document vsdoc = Jsoup.parse(responseparser.responseToString(ping)); Elements el = vsdoc.select("input"); String viewstate = (el.get(el.size() - 1).attr("value")); List<NameValuePair> formparams = new ArrayList<NameValuePair>(); formparams.add(new BasicNameValuePair("index_form", "index_form")); formparams.add(new BasicNameValuePair("index_form:question", questionString)); formparams.add(new BasicNameValuePair("index_form:eps", "")); formparams.add(new BasicNameValuePair("index_form:submitQuestion", "")); formparams.add(new BasicNameValuePair("javax.faces.ViewState", viewstate)); if(this.setLangPar){ formparams.add(new BasicNameValuePair("index_form:language", language)); } UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, Consts.UTF_8); httppost.setEntity(entity); HttpResponse response = client.execute(httppost); Document doc = Jsoup.parse(responseparser.responseToString(response)); Elements answer = doc.select("div.global-presentation-details>h3>a"); NodeVisitor nv = new NodeVisitor() { public void tail(Node node, int depth) { if (depth == 0) resultSet.add(node.attr("href")); } public void head(Node arg0, int arg1) { // do nothing here } }; answer.traverse(nv); question.setGoldenAnswers(resultSet); Elements codeElements = doc.select("div#sparqlQuery pre"); if (codeElements.size() > 0) { Element sparqlElement = codeElements.get(0); Elements codeChildren = sparqlElement.children(); for (Element c : codeChildren) { c.remove(); } question.setSparqlQuery(sparqlElement.text()); } }
Example #4
Source File: Node.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Perform a depth-first traversal through this node and its descendants. * @param nodeVisitor the visitor callbacks to perform on each node * @return this node, for chaining */ public Node traverse(NodeVisitor nodeVisitor) { Validate.notNull(nodeVisitor); NodeTraversor.traverse(nodeVisitor, this); return this; }
Example #5
Source File: Node.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Perform a depth-first traversal through this node and its descendants. * @param nodeVisitor the visitor callbacks to perform on each node * @return this node, for chaining */ public Node traverse(NodeVisitor nodeVisitor) { Validate.notNull(nodeVisitor); NodeTraversor.traverse(nodeVisitor, this); return this; }