本文整理汇总了Java中org.jsoup.nodes.Element.childNodeSize方法的典型用法代码示例。如果您正苦于以下问题:Java Element.childNodeSize方法的具体用法?Java Element.childNodeSize怎么用?Java Element.childNodeSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jsoup.nodes.Element
的用法示例。
在下文中一共展示了Element.childNodeSize方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: extractContent
import org.jsoup.nodes.Element; //导入方法依赖的package包/类
private String extractContent(String url) {
String summary = "";
try {
Document doc = Jsoup.connect(url).get();
Element element = doc.getElementById("intro").child(1);
if (element.childNodeSize() == 2) {
Element target = element.getElementsByClass("hidden").get(0);
summary = target.text();
} else {
summary = element.text();
}
} catch (Exception e) {
e.printStackTrace();
}
return summary;
}
示例2: getStringResNameAndValueMap
import org.jsoup.nodes.Element; //导入方法依赖的package包/类
/**
* 获取strings.xml 资源名-值 映射表
*
* @return
*/
protected Map<String, String> getStringResNameAndValueMap() {
Map<String, String> map = new HashMap<>();
Document document = getValuesXmlDocument();
Elements strings = document.getElementsByTag("string");
for (int i = 0; i < strings.size(); i++) {
Element element = strings.get(i);
String name = element.attr("name");
if (element.childNodeSize() > 0 && element.childNode(0) instanceof TextNode) {
String text = ((TextNode) element.childNode(0)).text();
map.put(name, text);
}
}
return map;
}
示例3: print2
import org.jsoup.nodes.Element; //导入方法依赖的package包/类
private void print2(String baseLocation) throws IOException, TransformerException, ParserConfigurationException {
Document document = Jsoup.connect(baseLocation).get();
Elements content = document.getElementsByAttributeValue("class", "entry-content");
String title = null;
ArrayList<String> list = new ArrayList<>();
for (Element div : content) {
List<Node> nodes = div.childNodes();
for (Node node : nodes) {
if (node instanceof Element) {
if (((Element) node).tagName().equals("h3")) {
writeFile(title, list);
list.clear();
System.out.println("Title: " + node.childNode(0));
title = node.childNode(0).toString();
} else if (((Element) node).tagName().equals("table")) {
//print table
Elements tr = ((Element) node).getElementsByTag("tr");
for (Element element : tr) {
Elements td = element.getElementsByTag("td");
for (Element value : td) {
if (value.childNodeSize() > 0) {
if (!(value.childNode(0) instanceof Comment)) {
// System.out.println("Emoticon: " + value.childNode(0) + " " + value.childNode(0).getClass().getSimpleName());
list.add(value.childNode(0).toString());
}
}
}
}
}
}
}
}
}
示例4: QuakeInfo
import org.jsoup.nodes.Element; //导入方法依赖的package包/类
public QuakeInfo(final Document doc) {
this.url = "https://typhoon.yahoo.co.jp"+Optional.ofNullable(doc.getElementById("history")).map(history -> history.getElementsByTag("tr").get(1).getElementsByTag("td").first().getElementsByTag("a").first().attr("href")).orElse("");
this.imageUrl = Optional.ofNullable(doc.getElementById("yjw_keihou").getElementsByTag("img").first()).map(image -> StringUtils.substringBefore(image.attr("src"), "?"));
final Element info = doc.getElementById("eqinfdtl");
final Map<String, String> data = info.getElementsByTag("table").get(0).getElementsByTag("tr").stream()
.map(tr -> tr.getElementsByTag("td")).collect(Collectors.toMap(td -> td.get(0).text(), td -> td.get(1).text()));
try {
this.announceTime = FORMAT.parse(data.get("情報発表時刻"));
final String quakeTime = data.get("発生時刻");
this.quakeTime = FORMAT.parse(StringUtils.substring(quakeTime, 0, quakeTime.length()-2));
this.epicenter = data.get("震源地");
this.lat = data.get("緯度");
this.lon = data.get("経度");
this.depth = data.get("深さ");
this.magnitude = NumberUtils.toFloat(data.get("マグニチュード"), -1f);
this.info = data.get("情報");
} catch (final ParseException e) {
throw new RuntimeException("Parse Error", e);
}
final Element yjw = info.getElementsByTag("table").get(1);
if (yjw.childNodeSize()<=1)
this.maxIntensity = Optional.empty();
else
this.maxIntensity = SeismicIntensity.get(yjw.getElementsByTag("td").first().getElementsByTag("td").first().text());
final Map<String, PrefectureDetail> details = new HashMap<>();
yjw.getElementsByTag("tr").stream().filter(tr -> tr.attr("valign").equals("middle")).forEach(tr -> {
final Optional<SeismicIntensity> intensity = SeismicIntensity.get(tr.getElementsByTag("td").first().getElementsByTag("td").first().text());
tr.getElementsByTag("table").first().getElementsByTag("tr").stream().map(line -> line.getElementsByTag("td")).collect(Collectors.toMap(td -> td.get(0).text(), td -> td.get(1).text())).entrySet().forEach(entry -> {
final String prefecture = entry.getKey();
final PrefectureDetail detail = details.computeIfAbsent(prefecture, key -> new PrefectureDetail(prefecture));
intensity.ifPresent(line -> Stream.of(StringUtils.split(entry.getValue(), " ")).forEach(str -> detail.addCity(line, str)));
});
});
this.details = new ArrayList<>(details.values());
Collections.sort(this.details, Comparator.reverseOrder());
}