use of org.jsoup.nodes.Element in project KaellyBot by Kaysoro.
the class Set method extractStatsFromTitleToList.
private static List<String> extractStatsFromTitleToList(Language lg, Element elem) {
List<String> values = new ArrayList<>();
Elements lines = elem.getElementsByClass("ak-title");
StringBuilder tmp = new StringBuilder();
for (Element line : lines) {
String value = EmojiManager.getEmojiForStat(lg, line.text()) + line.text() + "\n";
if (value.length() + tmp.length() > EmbedBuilder.FIELD_CONTENT_LIMIT) {
values.add(tmp.toString());
tmp.setLength(0);
} else
tmp.append(value);
}
if (tmp.length() > 0)
values.add(tmp.toString());
return values;
}
use of org.jsoup.nodes.Element in project KaellyBot by Kaysoro.
the class Set method getSet.
public static Set getSet(Language lg, String url) throws IOException {
Document doc = JSoupManager.getDocument(url);
String name = doc.getElementsByClass("ak-return-link").first().text();
String level = doc.getElementsByClass("ak-encyclo-detail-level").first().text().replaceAll(Translator.getLabel(lg, "set.extract.level") + " ", "");
Element element = doc.getElementsByClass("ak-encyclo-detail-illu").first().getElementsByTag("img").first();
String skinURL = element.attr("src");
List<String> bonusTotal = new ArrayList<>();
String composition = null;
String[] bonusPano = new String[doc.getElementsByClass("ak-item-list-preview").first().children().size() - 1];
List<String> recipeTotal = new ArrayList<>();
Elements titles = doc.getElementsByClass("ak-panel-title");
for (Element title : titles) if (title.text().equals(Translator.getLabel(lg, "set.extract.bonus.total")))
bonusTotal = extractStatsFromTitleToList(lg, title.parent());
else if (title.text().equals(Translator.getLabel(lg, "set.extract.bonus"))) {
for (int i = 0; i < bonusPano.length; i++) bonusPano[i] = extractStatsFromTitle(lg, title.parent().getElementsByClass("set-bonus-list set-bonus-" + (i + 2)).first());
} else if (title.text().equals(Translator.getLabel(lg, "set.extract.composition"))) {
StringBuilder st = new StringBuilder();
for (Element tr : title.parent().getElementsByTag("tr")) {
Element a = tr.getElementsByClass("ak-set-composition-name").first().getElementsByTag("a").first();
st.append("[").append(a.text()).append("](").append(a.attr("abs:href")).append(") ").append(tr.getElementsByClass("ak-set-composition-level").first().text()).append("\n");
}
composition = st.toString();
} else if (title.text().equals(Translator.getLabel(lg, "set.extract.recipe"))) {
Elements lines = title.parent().getElementsByClass("ak-column");
StringBuilder field = new StringBuilder();
for (Element line : lines) {
StringBuilder tmp = new StringBuilder(line.getElementsByClass("ak-front").text()).append(" [").append(line.getElementsByClass("ak-title").first().text()).append("](").append(line.getElementsByClass("ak-title").first().children().first().attr("abs:href")).append(")\n");
if (field.length() + tmp.length() > EmbedBuilder.FIELD_CONTENT_LIMIT) {
recipeTotal.add(field.toString());
field.setLength(0);
} else
field.append(tmp.toString());
}
if (field.length() > 0)
recipeTotal.add(field.toString());
}
return new Set(name, level, bonusTotal, URLManager.abs(skinURL), url, composition, bonusPano, recipeTotal);
}
use of org.jsoup.nodes.Element in project KaellyBot by Kaysoro.
the class Set method extractStatsFromTitle.
private static String extractStatsFromTitle(Language lg, Element elem) {
Elements lines = elem.getElementsByClass("ak-title");
StringBuilder tmp = new StringBuilder();
for (Element line : lines) tmp.append(EmojiManager.getEmojiForStat(lg, line.text())).append(line.text()).append("\n");
return tmp.toString();
}
use of org.jsoup.nodes.Element in project ocreader by schaal.
the class ArticleWebView method prepareDocument.
private void prepareDocument(Document document) {
// Some blog engines replace emojis with an image and place the emoji in the image tag.
// Find images with the tag being a single character and check if they are emoji. Then
// replace the img with the actual emoji in unicode.
Elements imgs = document.select("img[alt~=^.$]");
for (Element img : imgs) {
final String possibleEmoji = img.attr("alt");
if (EmojiManager.isEmoji(possibleEmoji))
img.replaceWith(new TextNode(possibleEmoji));
}
Elements iframes = document.getElementsByTag("iframe");
for (Element iframe : iframes) {
if (iframe.hasAttr("src")) {
String href = iframe.attr("src");
String html = String.format(Locale.US, videoLink, href, href);
// Check if url matches any known patterns
for (IframePattern iframePattern : IframePattern.values()) {
Matcher matcher = iframePattern.pattern.matcher(href);
if (matcher.matches()) {
final String videoId = matcher.group(2);
String urlPrefix = matcher.group(1);
href = urlPrefix + iframePattern.baseUrl + videoId;
// use thumbnail if available
if (iframePattern.thumbUrl != null) {
String thumbUrl = String.format(iframePattern.thumbUrl, urlPrefix, videoId);
html = String.format(Locale.US, videoThumbLink, href, thumbUrl);
}
break;
}
}
iframe.replaceWith(Jsoup.parse(html).body().child(0));
} else {
iframe.remove();
}
}
}
use of org.jsoup.nodes.Element in project JsoupXpath by zhegexiaohuozi.
the class XpathProcessor method visitAbbreviatedStep.
@Override
public XValue visitAbbreviatedStep(XpathParser.AbbreviatedStepContext ctx) {
if ("..".equals(ctx.getText())) {
Set<Element> total = new HashSet<>();
Elements newContext = new Elements();
for (Element e : currentScope().context()) {
total.add(e.parent());
}
newContext.addAll(total);
return XValue.create(newContext);
} else {
return XValue.create(currentScope().context());
}
}
Aggregations