Java Code Examples for org.jsoup.nodes.Element#getElementById()
The following examples show how to use
org.jsoup.nodes.Element#getElementById() .
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: AnalyzeByJSoup.java From a with GNU General Public License v3.0 | 6 votes |
private Elements filterElements(Elements elements, String[] rules) { if (rules == null || rules.length < 2) return elements; Elements selectedEls = new Elements(); for (Element ele : elements) { boolean isOk = false; switch (rules[0]) { case "class": isOk = ele.getElementsByClass(rules[1]).size() > 0; break; case "id": isOk = ele.getElementById(rules[1]) != null; break; case "tag": isOk = ele.getElementsByTag(rules[1]).size() > 0; break; case "text": isOk = ele.getElementsContainingOwnText(rules[1]).size() > 0; break; } if (isOk) { selectedEls.add(ele); } } return selectedEls; }
Example 2
Source File: AnalyzeByJSoup.java From MyBookshelf with GNU General Public License v3.0 | 6 votes |
private Elements filterElements(Elements elements, String[] rules) { if (rules == null || rules.length < 2) return elements; Elements selectedEls = new Elements(); for (Element ele : elements) { boolean isOk = false; switch (rules[0]) { case "class": isOk = ele.getElementsByClass(rules[1]).size() > 0; break; case "id": isOk = ele.getElementById(rules[1]) != null; break; case "tag": isOk = ele.getElementsByTag(rules[1]).size() > 0; break; case "text": isOk = ele.getElementsContainingOwnText(rules[1]).size() > 0; break; } if (isOk) { selectedEls.add(ele); } } return selectedEls; }
Example 3
Source File: JsoupParser.java From HaoReader with GNU General Public License v3.0 | 6 votes |
private Elements filterElements(Elements elements, String[] rules) { if (rules == null || rules.length < 2) return elements; final Elements selectedEls = new Elements(); for (Element ele : elements) { boolean isOk = false; switch (rules[0]) { case "class": isOk = ele.getElementsByClass(rules[1]).size() > 0; break; case "id": isOk = ele.getElementById(rules[1]) != null; break; case "tag": isOk = ele.getElementsByTag(rules[1]).size() > 0; break; case "text": isOk = ele.getElementsContainingOwnText(rules[1]).size() > 0; break; } if (isOk) { selectedEls.add(ele); } } return selectedEls; }
Example 4
Source File: MenuSoup.java From ShareBox with Apache License 2.0 | 6 votes |
@Override public void parse(Document root, Element head, Element body, Map<String, Object> values) { Element set = body.getElementById("menu-ease-mobile"); Elements childArr = set.getElementsByTag("a"); List<MenuModel> models = new ArrayList<>(); for (Element ele : childArr) { String title = ele.attr("title"); String url = ele.attr("href"); if (!title.equalsIgnoreCase("首页")) { MenuModel model = new MenuModel(title, url); models.add(model); } } //暂时去掉最后两个 每日更新 美女专题 models.remove(models.size() - 1); models.remove(models.size() - 1); values.put(TAG, models); }
Example 5
Source File: GANSWER2.java From NLIWOD with GNU Affero General Public License v3.0 | 5 votes |
@Override public void processQALDResp(HttpResponse response, IQuestion question) throws JsonParseException, JsonMappingException, UnsupportedOperationException, IOException { HashSet<String> resultSet = new HashSet<String>(); Document doc = Jsoup.parse(responseparser.responseToString(response)); Element container = doc.getElementById("myTabContent"); Element table = container.select("table").get(0); if(table.getElementById("hit") == null) return; Elements rows = table.select("tr"); for(Element row: rows) { Elements cols = row.select("td"); for(Element col: cols){ Element hit = col.getElementById("hit"); Element url = col.getElementById("entity_name"); Element value = col.getElementById("values"); if(url != null && value != null) { resultSet.add(value.ownText()); } else if(url != null) { resultSet.add(url.attr("href")); } else { resultSet.add(hit.ownText()); } } } question.setGoldenAnswers(resultSet); }
Example 6
Source File: BundleParserTest.java From flow with Apache License 2.0 | 5 votes |
@Test public void parseTemplateElement_stringContentNotSeenAsComment() { String source = "static get template() { return html`<vaadin-text-field label=\"Nats Url(s)\" placeholder=\"nats://server:port\" id=\"natsUrlTxt\" style=\"width:100%\"></vaadin-text-field>`;}"; Element element = BundleParser.parseTemplateElement("nats.js", source); Element natsElement = element.getElementById("natsUrlTxt"); Assert.assertNotNull("Found element by Id", natsElement); Assert.assertEquals("Invalid tag for element", "vaadin-text-field", natsElement.tagName()); Assert.assertEquals( "Parsed value for attribute 'placeholder' was wrong.", "nats://server:port", natsElement.attr("placeholder")); }
Example 7
Source File: ParseV9PronVideo.java From v9porn with MIT License | 4 votes |
/** * 解析其他类别 * * @param html 类别 * @return 列表 */ public static BaseResult<List<V9PornItem>> parseByCategory(String html) { Document doc = Jsoup.parse(html); Element body = doc.getElementById("wrapper"); Element container = body.selectFirst("div.container"); List<V9PornItem> v9PornItemList = parserByDivContainer(container); // get page info int totalPage = 1; Element paging = body.getElementById("paging"); Elements a = paging.select("a"); if (a.size() > 2) { String ppp = a.get(a.size() - 2).text(); if (TextUtils.isDigitsOnly(ppp)) { totalPage = Integer.parseInt(ppp); //Logger.d("总页数:" + totalPage); } } /* int totalPage = 1; List<V9PornItem> v9PornItemList = new ArrayList<>(); Document doc = Jsoup.parse(html); Element body = doc.getElementById("fullside"); Elements listchannel = body.getElementsByClass("listchannel"); for (Element element : listchannel) { V9PornItem v9PornItem = new V9PornItem(); String contentUrl = element.select("a").first().attr("href"); //Logger.d(contentUrl); contentUrl = contentUrl.substring(0, contentUrl.indexOf("&")); // Logger.d(contentUrl); String viewKey = contentUrl.substring(contentUrl.indexOf("=") + 1); v9PornItem.setViewKey(viewKey); String imgUrl = element.select("a").first().select("img").first().attr("src"); // Logger.d(imgUrl); v9PornItem.setImgUrl(imgUrl); String title = element.select("a").first().select("img").first().attr("title"); // Logger.d(title); v9PornItem.setTitle(title); String allInfo = element.text(); int sindex = allInfo.indexOf("时长"); String duration = allInfo.substring(sindex + 3, sindex + 8); v9PornItem.setDuration(duration); int start = allInfo.indexOf("添加时间"); String info = allInfo.substring(start); v9PornItem.setInfo(info.replace("还未被评分", "")); // Logger.d(info); v9PornItemList.add(v9PornItem); } //总页数 Element pagingnav = body.getElementById("paging"); Elements a = pagingnav.select("a"); if (a.size() > 2) { String ppp = a.get(a.size() - 2).text(); if (TextUtils.isDigitsOnly(ppp)) { totalPage = Integer.parseInt(ppp); // Logger.d("总页数:" + totalPage); } } */ BaseResult<List<V9PornItem>> baseResult = new BaseResult<>(); baseResult.setTotalPage(totalPage); baseResult.setData(v9PornItemList); return baseResult; }