當前位置: 首頁>>代碼示例>>Java>>正文


Java Element.textNodes方法代碼示例

本文整理匯總了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;
}
 
開發者ID:ThirtyDegreesRay,項目名稱:OpenHub,代碼行數:38,代碼來源:RepositoriesPresenter.java

示例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;
}
 
開發者ID:ThirtyDegreesRay,項目名稱:OpenHub,代碼行數:48,代碼來源:RepositoriesPresenter.java


注:本文中的org.jsoup.nodes.Element.textNodes方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。