List of usage examples for org.jsoup.nodes Element text
public String text()
From source file:me.vertretungsplan.parser.UntisCommonParser.java
static void handleRoom(Substitution subst, Element cell) { cell = getContentElement(cell);//from ww w . j a va 2s .c o m if (cell.select("s").size() > 0) { subst.setPreviousRoom(cell.select("s").text()); if (cell.ownText().length() > 0) { subst.setRoom(cell.ownText().replaceFirst("^\\?", "").replaceFirst("", "")); } } else { subst.setRoom(cell.text()); } }
From source file:me.vertretungsplan.parser.UntisCommonParser.java
static void handleSubject(Substitution subst, Element cell) { cell = getContentElement(cell);/*from w w w . jav a 2s . com*/ if (cell.select("s").size() > 0) { subst.setPreviousSubject(cell.select("s").text()); if (cell.ownText().length() > 0) { subst.setSubject(cell.ownText().replaceFirst("^\\?", "").replaceFirst("", "")); } } else { subst.setSubject(cell.text()); } }
From source file:emily.command.fun.FMLCommand.java
private void getFMLItems() { try {//w w w.j a v a 2 s. c om Document document = Jsoup.connect("http://fmylife.com/random").timeout(30_000) .userAgent(BotConfig.USER_AGENT).get(); if (document != null) { Elements fmls = document.select("p.block a[href^=/article/]"); for (Element fml : fmls) { items.add(fml.text().trim()); } } } catch (IOException e) { Launcher.logToDiscord(e, "fml-command", "boken"); } }
From source file:io.seldon.importer.articles.dynamicextractors.AllElementsTextListValueDynamicExtractor.java
@Override public String extract(AttributeDetail attributeDetail, String url, Document articleDoc) throws Exception { String attrib_value = null;//from ww w.ja v a 2s . c o m if ((attributeDetail.extractor_args != null) && (attributeDetail.extractor_args.size() >= 1)) { String cssSelector = attributeDetail.extractor_args.get(0); Elements elements = articleDoc.select(cssSelector); if (StringUtils.isNotBlank(cssSelector)) { if (elements != null) { StringBuilder sb = new StringBuilder(); boolean isFirstInList = true; for (Element e : elements) { String eText = e.text(); eText = StringUtils.strip(eText); if (StringUtils.isBlank(eText)) continue; eText = eText.toLowerCase(); if (isFirstInList) { isFirstInList = false; } else { sb.append(","); } sb.append(eText); } attrib_value = sb.toString(); } } } return attrib_value; }
From source file:com.megatome.j2d.support.JavadocSupport.java
private static List<SearchIndexValue> indexClassFile(File f) throws BuilderException { final List<SearchIndexValue> values = new ArrayList<>(); final Elements elements = loadAndFindLinks(f); String lastContext = ""; for (final Element e : elements) { Element parent = e.parent(); if (!parent.child(0).equals(e)) { continue; }/*from w w w . j a v a2 s. com*/ if (e.hasAttr("name")) { lastContext = e.attr("name"); } final String parentTagName = parent.tagName(); final String parentClassName = parent.className(); if (parentPattern.matcher(parentTagName).matches()) { parent = parent.parent(); if (!parent.child(0).equals(e.parent())) { continue; } } if (!containsIgnoreCase(parentTagName, "span") || !containsIgnoreCase(parentClassName, "memberNameLink") || equalsIgnoreCase("nested.class.summary", lastContext) || equalsIgnoreCase("enum.constant.summary", lastContext)) { continue; } final String text = parent.text(); final MatchType type = getMatchingType(lastContext, null); if (null == type) { System.err.println( String.format("Unknown type found. Please submit a bug report. (Text: %s, Context: %s)", text, lastContext)); continue; } try { final String linkPath = URLDecoder.decode(e.attr("href"), "UTF-8").replaceAll("\\.\\.\\/", ""); values.add(new SearchIndexValue(text, type, linkPath)); } catch (UnsupportedEncodingException ex) { throw new BuilderException("Error decoding a link", ex); } } return values; }
From source file:com.dsh105.nexus.command.module.information.TimeCommand.java
@Override public boolean onCommand(CommandPerformEvent event) { if (event.getArgs().length > 0) { String args = StringUtil.combineSplit(0, event.getArgs(), " "); try {/*from w w w .j a v a2s . co m*/ HttpResponse<JsonNode> jsonResponse = Unirest.get(GOOGLE_COORDS_URL + args) .header("accept", "application/json").asJson(); JSONArray response = jsonResponse.getBody().getObject().getJSONArray("results"); if (!jsonResponse.getBody().getObject().getString("status").equalsIgnoreCase("OK")) { event.errorWithPing("Invalid request"); } else { double lat = response.getJSONObject(0).getJSONObject("geometry").getJSONObject("location") .getDouble("lat"); double lng = response.getJSONObject(0).getJSONObject("geometry").getJSONObject("location") .getDouble("lng"); String loc = response.getJSONObject(0).getString("formatted_address"); Document doc = Jsoup.connect(TIME_URL + lat + "/" + lng).get(); Element timeEl = doc.select("localtime").first(); String time = timeEl.text(); event.respond("Time in " + Colors.BOLD + loc + ": " + time); return true; } } catch (Exception e) { throw new TimeDataLookupException("An error occurred in the lookup process", e); } } else { return false; } return true; }
From source file:org.commonjava.indy.ftest.core.urls.StoreOneAndVerifyInHtmlListingTest.java
@Test public void storeOneFileAndVerifyItInParentDirectoryListing() throws Exception { final byte[] data = "this is a test".getBytes(); final ByteArrayInputStream stream = new ByteArrayInputStream(data); final String root = "/path/to/"; final String path = root + "foo.txt"; client.content().store(hosted, STORE, path, stream); final IndyClientHttp http = getHttp(); final HttpGet request = http.newRawGet(client.content().contentUrl(hosted, STORE, root)); request.addHeader("Accept", "text/html"); final CloseableHttpClient hc = http.newClient(); final CloseableHttpResponse response = hc.execute(request); final InputStream listing = response.getEntity().getContent(); final String html = IOUtils.toString(listing); // TODO: Charset!! final Document doc = Jsoup.parse(html); for (final Element item : doc.select("a.item-link")) { final String fname = item.text(); System.out.printf("Listing contains: '%s'\n", fname); final String href = item.attr("href"); final String expected = client.content().contentUrl(hosted, STORE, root, fname); assertThat(fname + " does not have a href", href, notNullValue()); assertThat(fname + " has incorrect link: '" + href + "' (" + href.getClass().getName() + ")\nshould be: '" + expected + "' (String)", href, equalTo(expected)); }/*from w w w. j a v a 2s .com*/ }
From source file:org.commonjava.aprox.folo.ftest.urls.StoreOneAndVerifyInHtmlListingTest.java
@Test public void storeOneFileAndVerifyItInParentDirectoryListing() throws Exception { final byte[] data = "this is a test".getBytes(); final ByteArrayInputStream stream = new ByteArrayInputStream(data); final String root = "/path/to/"; final String path = root + "foo.txt"; final String track = "track"; content.store(track, hosted, STORE, path, stream); final AproxClientHttp http = getHttp(); final HttpGet request = http.newRawGet(content.contentUrl(track, hosted, STORE, root)); request.addHeader("Accept", "text/html"); final CloseableHttpClient hc = http.newClient(); final CloseableHttpResponse response = hc.execute(request); final InputStream listing = response.getEntity().getContent(); final String html = IOUtils.toString(listing); // TODO: Charset!! final Document doc = Jsoup.parse(html); for (final Element item : doc.select("a.item-link")) { final String fname = item.text(); System.out.printf("Listing contains: '%s'\n", fname); final String href = item.attr("href"); final String expected = client.content().contentUrl(hosted, STORE, root, fname); assertThat(fname + " does not have a href", href, notNullValue()); assertThat(fname + " has incorrect link: '" + href + "' (" + href.getClass().getName() + ")\nshould be: '" + expected + "' (String)", href, equalTo(expected)); }/*from w w w .j a va2 s.co m*/ }
From source file:org.commonjava.indy.folo.ftest.urls.StoreOneAndVerifyInHtmlListingTest.java
@Test public void storeOneFileAndVerifyItInParentDirectoryListing() throws Exception { final byte[] data = "this is a test".getBytes(); final ByteArrayInputStream stream = new ByteArrayInputStream(data); final String root = "/path/to/"; final String path = root + "foo.txt"; final String track = "track"; content.store(track, hosted, STORE, path, stream); final IndyClientHttp http = getHttp(); final HttpGet request = http.newRawGet(content.contentUrl(track, hosted, STORE, root)); request.addHeader("Accept", "text/html"); final CloseableHttpClient hc = http.newClient(); final CloseableHttpResponse response = hc.execute(request); final InputStream listing = response.getEntity().getContent(); final String html = IOUtils.toString(listing); // TODO: Charset!! final Document doc = Jsoup.parse(html); for (final Element item : doc.select("a.item-link")) { final String fname = item.text(); System.out.printf("Listing contains: '%s'\n", fname); final String href = item.attr("href"); final String expected = client.content().contentUrl(hosted, STORE, root, fname); assertThat(fname + " does not have a href", href, notNullValue()); assertThat(fname + " has incorrect link: '" + href + "' (" + href.getClass().getName() + ")\nshould be: '" + expected + "' (String)", href, equalTo(expected)); }// w w w .ja v a 2 s . com }
From source file:org.commonjava.indy.ftest.core.urls.StoreOneAndSourceStoreUrlInHtmlListingTest.java
@Test public void storeOneFileAndVerifyItInParentDirectoryListing() throws Exception { final byte[] data = "this is a test".getBytes(); final ByteArrayInputStream stream = new ByteArrayInputStream(data); final String root = "/path/to/"; final String path = root + "foo.txt"; client.content().store(hosted, STORE, path, stream); final IndyClientHttp http = getHttp(); final HttpGet request = http.newRawGet(client.content().contentUrl(hosted, STORE, root)); request.addHeader("Accept", "text/html"); final CloseableHttpClient hc = http.newClient(); final CloseableHttpResponse response = hc.execute(request); final InputStream listing = response.getEntity().getContent(); final String html = IOUtils.toString(listing); // TODO: Charset!! final Document doc = Jsoup.parse(html); for (final Element item : doc.select("a.source-link")) { final String fname = item.text(); System.out.printf("Listing contains: '%s'\n", fname); final String href = item.attr("href"); final String expected = client.content().contentUrl(hosted, STORE); assertThat(fname + " does not have a href", href, notNullValue()); assertThat(fname + " has incorrect link: '" + href + "' (" + href.getClass().getName() + ")\nshould be: '" + expected + "' (String)", href, equalTo(expected)); }//from w ww .jav a2 s. c o m }