use of org.jsoup.select.Elements in project CodeUtils by boredream.
the class Main method parseApi.
private static ArrayList<RequestInfo> parseApi(String typeUrl) {
ArrayList<RequestInfo> requestInfos = new ArrayList<RequestInfo>();
try {
String response = BmobHttpUtils.getString(typeUrl);
Document parse = Jsoup.parse(response);
Elements refentryElements = parse.getElementsByClass("refentry");
for (Element element : refentryElements) {
Elements hrefElement = element.getElementsByAttribute("href");
if (hrefElement.size() > 0) {
Element e = hrefElement.get(0);
String link = e.attr("href");
RequestInfo info = getApiInfo(link);
requestInfos.add(info);
}
}
} catch (Exception e) {
e.printStackTrace();
}
return requestInfos;
}
use of org.jsoup.select.Elements in project LeMondeRssReader by MBach.
the class ArticleActivity method extractComments.
private List<Model> extractComments(Element doc, boolean loadMoreComments) {
List<Model> commentList = new ArrayList<>();
// Extract header
if (!loadMoreComments) {
Elements header = doc.select("[itemprop='InteractionCount']");
if (atLeastOneChild(header)) {
TextView commentHeader = new TextView(getBaseContext());
commentHeader.setText(String.format("Commentaires %s", header.text()));
commentHeader.setTypeface(null, Typeface.BOLD);
commentHeader.setTextColor(Color.WHITE);
commentHeader.setPadding(0, 0, 0, Constants.PADDING_COMMENT_ANSWER);
commentList.add(new Model(commentHeader, 0));
}
}
// Extract comments
Elements comments = doc.select("[itemprop='commentText']");
for (Element comment : comments) {
Elements refs = comment.select("p.references");
if (atLeastOneChild(refs)) {
// Clear date
refs.select("span").remove();
TextView author = new TextView(getBaseContext());
author.setTypeface(null, Typeface.BOLD);
author.setText(refs.text());
author.setTextColor(Color.WHITE);
Elements commentComment = refs.next();
if (atLeastOneChild(commentComment)) {
TextView content = new TextView(getBaseContext());
content.setText(commentComment.first().text());
content.setTextColor(Color.WHITE);
if (comment.hasClass("reponse")) {
author.setPadding(Constants.PADDING_COMMENT_ANSWER, 0, 0, 12);
content.setPadding(Constants.PADDING_COMMENT_ANSWER, 0, 0, 16);
} else {
author.setPadding(0, 0, 0, 12);
content.setPadding(0, 0, 0, 16);
}
Integer commentId = Integer.valueOf(comment.attr("data-reaction_id"));
commentList.add(new Model(author, commentId));
commentList.add(new Model(content, commentId));
}
}
}
// Extract full comments page URI
Elements div = doc.select("div.reactions");
if (atLeastOneChild(div)) {
Element fullComments = div.first().nextElementSibling();
Elements next = fullComments.select("a");
if (atLeastOneChild(next)) {
commentsURI = next.first().attr("href");
}
}
return commentList;
}
use of org.jsoup.select.Elements in project LeMondeRssReader by MBach.
the class ArticleActivity method extractDates.
@NonNull
private String extractDates(@NonNull Element article) {
StringBuilder builder = new StringBuilder("");
Elements datePublished = article.select("[itemprop='datePublished']");
if (!datePublished.isEmpty()) {
builder.append("Publié le ").append(datePublished.first().text());
}
Elements dateModified = article.select("[itemprop='dateModified']");
if (!dateModified.isEmpty()) {
builder.append(", modifié le ").append(dateModified.first().text());
}
return builder.toString();
}
use of org.jsoup.select.Elements in project opennms by OpenNMS.
the class HttpCollectionHandler method getTimeStamp.
/**
* Gets the time stamp.
*
* @param document the JSoup document
* @param group the group
* @return the time stamp
*/
protected Date getTimeStamp(Document doc, XmlGroup group) {
if (group.getTimestampXpath() == null) {
return null;
}
String pattern = group.getTimestampFormat() == null ? "yyyy-MM-dd HH:mm:ss" : group.getTimestampFormat();
LOG.debug("getTimeStamp: retrieving custom timestamp to be used when updating RRDs using selector {} and pattern {}", group.getTimestampXpath(), pattern);
Elements el = doc.select(group.getTimestampXpath());
if (el == null) {
return null;
}
String value = el.html();
Date date = null;
try {
DateTimeFormatter dtf = DateTimeFormat.forPattern(pattern);
DateTime dateTime = dtf.parseDateTime(value);
date = dateTime.toDate();
} catch (Exception e) {
LOG.warn("getTimeStamp: can't convert custom timetime {} using pattern {}", value, pattern);
}
return date;
}
use of org.jsoup.select.Elements in project anton-pavlovich-bot by wyvie.
the class SlovnikCommand method parseHtml.
private List<List<String>> parseHtml(String source) {
List<List<String>> blocks = new ArrayList<>();
Document document = Jsoup.parse(source);
Elements results = document.select("div#results");
// #results > div > h1 - subject itself or nothing have been found message
List<String> headFastDefLine = new ArrayList<>();
headFastDefLine.add(String.format("<b>%s</b>", results.select("h1").text()));
results.select("#fastMeanings a").forEach(element -> {
String hrefNew = BASE_SLOVNIK_URL + element.attr("href");
element = element.attr("href", hrefNew);
headFastDefLine.add(element.toString());
});
// extended grammatics
List<String> extDefs = new ArrayList<>();
results.select("ol li dl").forEach(dl -> {
Element dt = dl.selectFirst("dt");
String def = dt.text();
String aTagsDefs = dt.select("a").stream().map(e -> {
String hrefNew = BASE_SLOVNIK_URL + e.attr("href");
return e.attr("href", hrefNew).toString();
}).collect(Collectors.joining(","));
extDefs.add(String.format("%s %s", aTagsDefs, def));
dl.select("dd").forEach(dd -> {
extDefs.add(dd.wholeText());
});
});
// additional definitions links
List<String> moreDefs = new ArrayList<>();
results.select("ul.moreResults li").forEach(li -> {
Element aTag = li.selectFirst("a");
li.selectFirst("a").remove();
String hrefNew = BASE_SLOVNIK_URL + aTag.attr("href");
aTag = aTag.attr("href", hrefNew);
String liText = li.text();
moreDefs.add(String.format("%s <i>%s</i>", aTag, liText));
});
// synonyms/antonyms
List<String> synDefs = new ArrayList<>();
results.select("div.other-meaning a").forEach(a -> {
String hrefNew = BASE_SLOVNIK_URL + a.attr("href");
synDefs.add(a.attr("href", hrefNew).toString());
});
// additional definitions links
List<String> addDefs = new ArrayList<>();
results.select("#fulltext li").forEach(li -> {
Element aTag = li.selectFirst("a");
li.selectFirst("a").remove();
String hrefNew = BASE_SLOVNIK_URL + aTag.attr("href");
aTag = aTag.attr("href", hrefNew);
String liText = li.text();
addDefs.add(String.format("%s <i>%s</i>", aTag, liText));
});
blocks.add(headFastDefLine);
blocks.add(extDefs);
blocks.add(synDefs);
blocks.add(moreDefs);
blocks.add(addDefs);
return blocks;
}
Aggregations