List of usage examples for org.jsoup.nodes Element childNodes
List childNodes
To view the source code for org.jsoup.nodes Element childNodes.
Click Source Link
From source file:Main.java
public static String ownText(Element element) { StringBuilder builder = new StringBuilder(); for (Node child : element.childNodes()) { if (child instanceof TextNode) { TextNode textNode = (TextNode) child; appendNormalisedText(builder, textNode); } else if (child instanceof Element) { appendNewlineIfBr((Element) child, builder); }//from w w w .j a v a 2 s. co m } return builder.toString().trim(); }
From source file:io.apiman.tools.i18n.TemplateScanner.java
/** * @param element// w w w .j a v a2 s .c o m * @return true if the element doesn't have any child elements */ private static boolean hasNoChildren(Element element) { List<Node> childNodes = element.childNodes(); for (Node node : childNodes) { if (node instanceof Element) { return false; } } return true; }
From source file:de.luhmer.owncloudnewsreader.reader.GoogleReaderApi.GoogleReaderMethods.java
@SuppressWarnings("unused") public static ArrayList<FolderSubscribtionItem> getSubList(String _USERNAME, String _PASSWORD) throws UnsupportedEncodingException, IOException { ArrayList<FolderSubscribtionItem> _SUBTITLE_ARRAYLIST = new ArrayList<FolderSubscribtionItem>(); Document doc = Jsoup.connect(GoogleReaderConstants._SUBSCRIPTION_LIST_URL) .header("Authorization", GoogleReaderConstants._AUTHPARAMS + AuthenticationManager.getGoogleAuthKey(_USERNAME, _PASSWORD)) .userAgent(GoogleReaderConstants.APP_NAME).timeout(5000).get(); Elements objects = doc.select("object"); Element element = objects.get(0); Node childTemp = element.childNodes().get(0); List<Node> childs = childTemp.childNodes(); for (Node node : childs) { Elements links = ((Element) node).select("string"); String idFeed = null;/* w w w . j av a 2s . c o m*/ String feedName; String parentSubscriptionName; for (Element link : links) { String tagAttrib = link.attr("name"); String tagText = link.text(); if (tagAttrib.equals("id") && idFeed == null) idFeed = tagText; else if (tagAttrib.equals("title")) feedName = tagText; else if (tagAttrib.equals("label")) parentSubscriptionName = tagText; } //String idFeed = node.attr("id"); //String name = node.attr("title"); //_SUBTITLE_ARRAYLIST.add(new FolderSubscribtionItem(feedName, -1, idFeed, parentSubscriptionName));//TODO implements this again... ? Update FolderSubscribtionItem } //String[] _SUBTITLE_ARRAY = new String[_SUBTITLE_ARRAYLIST.size()]; //_SUBTITLE_ARRAYLIST.toArray(_SUBTITLE_ARRAY); return _SUBTITLE_ARRAYLIST; }
From source file:org.jresponder.util.TextUtil.java
/** * @param cell element that contains whitespace formatting * @return/* w ww . j a va 2 s. c o m*/ */ public String getWholeText(Element cell) { String text = null; List<Node> childNodes = cell.childNodes(); if (childNodes.size() > 0) { Node childNode = childNodes.get(0); if (childNode instanceof TextNode) { text = ((TextNode) childNode).getWholeText(); } } if (text == null) { text = cell.text(); } return text; }
From source file:mobi.jenkinsci.ci.client.sso.GoogleSsoHandler.java
private String getDivText(final Element errorDiv) { for (final Node child : errorDiv.childNodes()) { if (child instanceof TextNode) { return ((TextNode) child).getWholeText().trim(); }//from w w w . j a v a 2 s .c o m } return ""; }
From source file:model.ParseInfoFromSite.java
/** * Clear page from all comments. Its give access to some closed information * //from w ww. j a v a2 s. c o m * @param doc * @return */ public List<Comment> findAllComments(Document doc) { logger.info("run"); List<Comment> comments = new ArrayList<>(); for (Element element : doc.getAllElements()) { for (Node n : element.childNodes()) { if (n.nodeName().equals("#comment")) { comments.add((Comment) n); } } } return Collections.unmodifiableList(comments); }
From source file:com.decker.parkingSearch.receiver.ParkingContentReceiver.java
public void fetch() throws IOException { Document doc = Jsoup.connect(this.baseUrl).get(); Elements detailBox = doc.select("td[style=\"vertical-align:top;\"]"); for (Element es : detailBox) { try {/*from w w w . ja v a2s . co m*/ Park detail = new Park(); detail.name = es.childNode(0) instanceof Element ? ((Element) es.childNode(0)).text() : ""; detail.address = ""; for (int i = 1; i < es.childNodes().size() - 1; i++) { String content = (es.childNodes().get(i)).toString(); if (content.equals((es.childNodes().get(i + 1)).toString())) { break; } else { if (!content.equals("<br>")) { detail.address += (StringEscapeUtils.unescapeHtml(content) + " "); } } } if (es.select("span > a").size() == 0) { continue; } String secretContent = StringEscapeUtils .unescapeHtml(es.select("span > a").get(0).attr("href").replaceAll("\"", "")); Matcher matcher = Pattern.compile("(?<=javascript\\:count\\().*(?=\\))").matcher(secretContent); String[] secretInfoList; if (matcher.find()) { secretInfoList = matcher.group().split(","); } else { continue; } String mobContent = Jsoup .connect(String.format("http://www.goseeaustralia.com.au/statslookup.asp?keyID=%s&StatID=0", secretInfoList[1])) .get().text(); detail.mobileNumber = StringUtils.isNotBlank(mobContent) ? mobContent : ""; String phoneContent = Jsoup .connect(String.format("http://www.goseeaustralia.com.au/statslookup.asp?keyID=%s&StatID=1", secretInfoList[1])) .get().text(); detail.phoneNumber = StringUtils.isNotBlank(phoneContent) ? phoneContent : ""; String faxContent = Jsoup .connect(String.format("http://www.goseeaustralia.com.au/statslookup.asp?keyID=%s&StatID=2", secretInfoList[1])) .get().text(); detail.faxNumber = StringUtils.isNotBlank(faxContent) ? faxContent : ""; detail.email = StringUtils.isNotBlank(secretInfoList[2]) ? secretInfoList[2] : ""; this.info.parks.add(detail); } catch (Exception ex) { System.out.printf("Error during fetch %s park with url %s %n", es.childNode(0).toString(), this.baseUrl); ex.printStackTrace(); } } }
From source file:sample.ui.mvc.MessageController.java
private String getBidId(Message message) { try {/* ww w. ja v a2s . c o m*/ BasicCookieStore cookieStore = new BasicCookieStore(); CloseableHttpClient httpclient = HttpClients.custom().setDefaultCookieStore(cookieStore).build(); doLogin(cookieStore, httpclient, ZHANGDAIYIXIAN); // String bidName = message.getBidName(); // time // String mainUrl = "http://www.wujinsuo.cn:80/index.php"; HttpGet httpget = new HttpGet(mainUrl); httpget.addHeader("Accept", ACCEPT); httpget.addHeader("User-Agent", AGENT); ResponseHandler<String> responseHandler = new ResponseHandler<String>() { public String handleResponse(final HttpResponse response) throws ClientProtocolException, IOException { int status = response.getStatusLine().getStatusCode(); if (status >= 200 && status < 300) { HttpEntity entity = response.getEntity(); return entity != null ? EntityUtils.toString(entity) : null; } else { throw new ClientProtocolException("Unexpected response status: " + status); } } }; String resultString = httpclient.execute(httpget, responseHandler); // parse html Document doc = Jsoup.parse(resultString); Elements links = doc.select("a[href]"); Element aElement = null; for (Element e : links) { List<Node> childNode = e.childNodes(); if (childNode.size() != 1) continue; Node node = childNode.get(0); if ("span".equals(node.nodeName())) { String html = node.outerHtml(); logger.info(html); if (html.contains(bidName)) { // okle aElement = e; } } } if (aElement == null) { // retry return ""; } else { String href = aElement.attr("href"); String bidId = StringUtils.substringAfter(href, "id="); logger.info(bidId); return bidId; } } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (URISyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
From source file:mml.handler.post.MMLPostHTMLHandler.java
/** * May happen but should not//from ww w. j a v a 2 s . c o m * @param elem an element that is not a span, p or div */ private void parseOtherElement(Element elem) throws JSONException { List<Node> children = elem.childNodes(); int offset = sb.length(); String name = elem.attr("class"); if (name == null || name.length() == 0) name = elem.nodeName(); Range r = new Range(name, offset, 0); stil.add(r); for (Node child : children) { if (child instanceof Element) parseOtherElement((Element) child); else if (child instanceof TextNode) sb.append(((TextNode) child).getWholeText()); } this.stil.updateLen(r, sb.length() - offset); prevWasMilestone = false; }
From source file:mml.handler.post.MMLPostHTMLHandler.java
/** * Parse a div (section)// w w w . ja v a 2 s . c o m * @param div the div * @throws JSONException */ private void parseDiv(Element div) throws JSONException { List<Node> children = div.childNodes(); int offset = sb.length(); String name = div.attr("class"); if (name == null || name.length() == 0) name = "section"; Range r = new Range(name, offset, 0); stil.add(r); for (Node child : children) { if (child instanceof Element) { String nName = child.nodeName().toLowerCase(); if (nName.equals("p")) parsePara((Element) child, "p"); else if (nName.matches("(h|H)\\d")) parsePara((Element) child, nName); else if (child.nodeName().toLowerCase().equals("span")) parseSpan((Element) child); else if (nName.equals("pre")) parsePre((Element) child); else parseOtherElement((Element) child); } } ensure(3, true); this.stil.updateLen(r, sb.length() - offset); prevWasMilestone = false; }