本文整理汇总了Java中org.jsoup.nodes.Element.textNodes方法的典型用法代码示例。如果您正苦于以下问题:Java Element.textNodes方法的具体用法?Java Element.textNodes怎么用?Java Element.textNodes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jsoup.nodes.Element
的用法示例。
在下文中一共展示了Element.textNodes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseCollectionsRepositoryData
import org.jsoup.nodes.Element; //导入方法依赖的package包/类
private Repository parseCollectionsRepositoryData(Element element) throws Exception{
String fullName = element.select("div > div > a").attr("href");
String owner = fullName.substring(1, fullName.lastIndexOf("/"));
String repoName = fullName.substring(fullName.lastIndexOf("/") + 1);
String ownerAvatar = element.select("div > div > a > img").attr("src");
Elements articleElements = element.getElementsByTag("div");
Element descElement = articleElements.get(articleElements.size() - 2);
StringBuilder desc = new StringBuilder("");
for(TextNode textNode : descElement.textNodes()){
desc.append(textNode.getWholeText());
}
Element numElement = articleElements.last();
String starNumStr = numElement.select("a").get(0).textNodes().get(1).toString();
String forkNumStr = numElement.select("a").get(1).textNodes().get(1).toString();
String language = "";
Elements languageElements = numElement.select("span > span");
if(languageElements.size() > 0){
language = numElement.select("span > span").get(1).textNodes().get(0).toString();
}
Repository repo = new Repository();
repo.setFullName(fullName);
repo.setName(repoName);
User user = new User();
user.setLogin(owner);
user.setAvatarUrl(ownerAvatar);
repo.setOwner(user);
repo.setDescription(desc.toString());
repo.setStargazersCount(Integer.parseInt(starNumStr.replaceAll(" ", "")));
repo.setForksCount(Integer.parseInt(forkNumStr.replaceAll(" ", "")));
repo.setLanguage(language);
return repo;
}
示例2: parseTrendingRepositoryData
import org.jsoup.nodes.Element; //导入方法依赖的package包/类
private Repository parseTrendingRepositoryData(Element element) throws Exception{
String fullName = element.select("div > h3 > a").attr("href");
fullName = fullName.substring(1);
String owner = fullName.substring(0, fullName.lastIndexOf("/"));
String repoName = fullName.substring(fullName.lastIndexOf("/") + 1);
Element descElement = element.select("div > p").first();
StringBuilder desc = new StringBuilder("");
for(TextNode textNode : descElement.textNodes()){
desc.append(textNode.getWholeText());
}
Element numElement = element.getElementsByClass("f6 text-gray mt-2").first();
String language = "";
Elements languageElements = numElement.select("span > span");
if(languageElements.size() > 0){
language = numElement.select("span > span").get(1).textNodes().get(0).toString().trim();
}
String starNumStr = numElement.select("a").get(0).textNodes().get(1).toString()
.replaceAll(" ", "").replaceAll(",", "");
String forkNumStr = numElement.select("a").get(1).textNodes().get(1).toString()
.replaceAll(" ", "").replaceAll(",", "");
Element periodElement = numElement.getElementsByClass("d-inline-block float-sm-right").first();
String periodNumStr = "0";
if(periodElement != null){
periodNumStr = periodElement.childNodes().get(2).toString().trim();
periodNumStr = periodNumStr.substring(0, periodNumStr.indexOf(" "))
.replaceAll(",", "");
}
Repository repo = new Repository();
repo.setFullName(fullName);
repo.setName(repoName);
User user = new User();
user.setLogin(owner);
repo.setOwner(user);
repo.setDescription(desc.toString().trim()
.replaceAll("\n", ""));
repo.setStargazersCount(Integer.parseInt(starNumStr));
repo.setForksCount(Integer.parseInt(forkNumStr));
repo.setSinceStargazersCount(Integer.parseInt(periodNumStr));
repo.setLanguage(language);
repo.setSince(since);
return repo;
}