Java Code Examples for org.jsoup.nodes.Element#hasText()
The following examples show how to use
org.jsoup.nodes.Element#hasText() .
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: CnblogParser.java From java-tutorial with Creative Commons Attribution Share Alike 4.0 International | 6 votes |
/** * 获取指定页HTML 文档指定的body * * @throws IOException */ private static int printAllTitleInPage(String blogUrl, int page) throws IOException { int count = 0; Document doc = Jsoup.connect(blogUrl + "default.html?page=" + page).get(); Elements postTitles = doc.body().getElementsByClass("postTitle"); for (Element postTitle : postTitles) { Elements links = postTitle.getElementsByTag("a"); for (Element link : links) { if (link.hasText()) { System.out.println(link.text()); System.out.println(link.attr("href")); count++; } } } return count; }
Example 2
Source File: CoursesParser.java From ZfsoftCampusAssit with Apache License 2.0 | 6 votes |
private boolean isFetchCoursesHtmlSuccessful(String htmlContent){ boolean isFectchSuccess = false; Document loadCoursesDoc = Jsoup.parse(htmlContent); Element loadFlagElement = loadCoursesDoc.getElementById("Label1"); if (loadFlagElement != null && loadFlagElement.hasText()) { isFectchSuccess = CODE_COURSES_LOAD_SUCCESS.equals(loadFlagElement.text().trim()); Element collegeElement = loadCoursesDoc.getElementById("Label7"); Element majorElement = loadCoursesDoc.getElementById("Label8"); Element classElement = loadCoursesDoc.getElementById("Label9"); User loginUser = PreferenceUtil.getLoginUser(); loginUser.userCollege = collegeElement != null && collegeElement.hasText() ? StringUtil.parseUserFieldTextHtml(collegeElement.text(), 3, 0) : ""; loginUser.userMajor = majorElement != null && majorElement.hasText() ? StringUtil.parseUserFieldTextHtml(majorElement.text(), 3, 0) : ""; loginUser.userClass = classElement != null && classElement.hasText() ? StringUtil.parseUserFieldTextHtml(classElement.text(), 4, 0) : ""; PreferenceUtil.updateLoginUser(loginUser); } return isFectchSuccess; }
Example 3
Source File: HtmlHelper.java From FairEmail with GNU General Public License v3.0 | 5 votes |
private static boolean hasVisibleContent(List<Node> nodes) { for (Node node : nodes) if (node instanceof TextNode && !((TextNode) node).isBlank()) return true; else if (node instanceof Element) { Element element = (Element) node; if (!element.isBlock() && (element.hasText() || element.selectFirst("a") != null || element.selectFirst("img") != null)) return true; } return false; }
Example 4
Source File: DomDistance.java From apogen with Apache License 2.0 | 5 votes |
private static void getStringsToRemove(Elements allElements) { for (Element e : allElements) { if (e.hasText()) { stringsToRemove.add(e.ownText()); } getStringsToRemove(e.children()); } }
Example 5
Source File: LoginParser.java From ZfsoftCampusAssit with Apache License 2.0 | 5 votes |
private void parseLoiginUser(User loginFormUser,String loginUserHtml) { Document userDoc = Jsoup.parse(loginUserHtml); Element userNameElement = userDoc.getElementById("xhxm"); if (userNameElement != null && userNameElement.hasText()) { loginFormUser.userRealName = StringUtil.parseUserFieldTextHtml(userNameElement.text(), 0, 2); } }
Example 6
Source File: Elements.java From astor with GNU General Public License v2.0 | 5 votes |
public boolean hasText() { for (Element element: this) { if (element.hasText()) return true; } return false; }
Example 7
Source File: Elements.java From astor with GNU General Public License v2.0 | 5 votes |
/** Test if any matched Element has any text content, that is not just whitespace. @return true if any element has non-blank text content. @see Element#hasText() */ public boolean hasText() { for (Element element: this) { if (element.hasText()) return true; } return false; }
Example 8
Source File: Elements.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Get the text content of each of the matched elements. If an element has no text, then it is not included in the * result. * @return A list of each matched element's text content. * @see Element#text() * @see Element#hasText() * @see #text() */ public List<String> eachText() { ArrayList<String> texts = new ArrayList<>(size()); for (Element el: this) { if (el.hasText()) texts.add(el.text()); } return texts; }
Example 9
Source File: Elements.java From astor with GNU General Public License v2.0 | 5 votes |
/** Test if any matched Element has any text content, that is not just whitespace. @return true if any element has non-blank text content. @see Element#hasText() */ public boolean hasText() { for (Element element: this) { if (element.hasText()) return true; } return false; }
Example 10
Source File: Elements.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Get the text content of each of the matched elements. If an element has no text, then it is not included in the * result. * @return A list of each matched element's text content. * @see Element#text() * @see Element#hasText() * @see #text() */ public List<String> eachText() { ArrayList<String> texts = new ArrayList<>(size()); for (Element el: this) { if (el.hasText()) texts.add(el.text()); } return texts; }
Example 11
Source File: Elements.java From jsoup-learning with MIT License | 5 votes |
public boolean hasText() { for (Element element: contents) { if (element.hasText()) return true; } return false; }
Example 12
Source File: BaseParser.java From ZfsoftCampusAssit with Apache License 2.0 | 3 votes |
/** * 判断是否 ViewState 失效 * <p> * <div id="title_m">ERROR - 出错啦!</div> * * @param response * @return */ public boolean isViewStateInvalid(String response) { Element newerStateElement = Jsoup.parse(response).getElementById("title_m"); if (newerStateElement != null && newerStateElement.hasText()) { return newerStateElement.text().startsWith(PREFIX_ERR_VIEW_STATE_TITLE); } return false; }