Example usage for org.jsoup.nodes Element text

List of usage examples for org.jsoup.nodes Element text

Introduction

In this page you can find the example usage for org.jsoup.nodes Element text.

Prototype

public String text() 

Source Link

Document

Gets the combined text of this element and all its children.

Usage

From source file:net.meiolania.apps.habrahabr.fragments.posts.loader.PostShowLoader.java

@Override
public PostsFullData loadInBackground() {
    PostsFullData data = new PostsFullData();

    try {/*ww w .  j  a va  2s .  c o m*/
        Document document = Jsoup.connect(url).get();

        Element title = document.select("span.post_title").first();
        Element hubs = document.select("div.hubs").first();
        Element content = document.select("div.content").first();
        Element date = document.select("div.published").first();
        Element author = document.select("div.author > a").first();

        if (title != null) {
            data.setUrl(url);
            data.setTitle(title.text());
            data.setHubs(hubs.text());
            data.setContent(content.html());
            data.setDate(date.text());
            data.setAuthor(author.text());
        } else
            data.setContent(context.getString(R.string.error_404));
    } catch (IOException e) {
    }

    return data;
}

From source file:net.meiolania.apps.habrahabr.fragments.posts.loader.PostsLoader.java

@Override
public ArrayList<PostsData> loadInBackground() {
    ArrayList<PostsData> data = new ArrayList<PostsData>();

    try {/*from  w  w w  .jav  a2  s. co  m*/
        String readyUrl = url.replace("%page%", String.valueOf(page));

        Log.i(TAG, "Loading a page: " + readyUrl);

        Document document = Jsoup.connect(readyUrl).get();

        Elements posts = document.select("div.post");

        for (Element post : posts) {
            PostsData postsData = new PostsData();

            Element postTitle = post.select("a.post_title").first();
            Element hubs = post.select("div.hubs").first();
            Element date = post.select("div.published").first();
            Element author = post.select("div.author > a").first();
            Element comments = post.select("div.comments > span.all").first();
            Element score = post.select("span.score").first();

            postsData.setTitle(postTitle.text());
            postsData.setUrl(postTitle.attr("abs:href"));
            postsData.setHubs(hubs.text());
            postsData.setDate(date.text());
            postsData.setAuthor(author != null ? author.text() : "");
            postsData.setComments(comments != null ? comments.text() : "0");
            postsData.setScore(score.text());

            data.add(postsData);
        }
    } catch (IOException e) {
    }

    return data;
}

From source file:net.meiolania.apps.habrahabr.fragments.qa.loader.QaCommentsLoader.java

@Override
public ArrayList<CommentsData> loadInBackground() {
    ArrayList<CommentsData> data = new ArrayList<CommentsData>();

    try {/*from   ww  w .j a v  a 2  s. c  o  m*/
        Document document = Jsoup.connect(url).get();

        Elements answers = document.select("div.answer");

        for (Element answer : answers) {
            CommentsData commentsData = new CommentsData();

            Element name = answer.select("a.username").first();
            Element message = answer.select("div.message").first();
            Element linkToComment = answer.select("a.link_to_comment").first();
            Element score = answer.select("span.score").first();

            commentsData.setUrl(linkToComment.attr("abs:href"));
            commentsData.setAuthor(name.text());
            commentsData.setAuthorUrl(name.attr("abs:href"));
            commentsData.setComment(message.text());
            commentsData.setLevel(0);
            commentsData.setScore(score.text());

            data.add(commentsData);

            Elements comments = answer.select("div.comment_item");

            for (Element comment : comments) {
                commentsData = new CommentsData();

                name = comment.select("span.info > a").first();
                message = comment.select("span.text").first();

                commentsData.setUrl(linkToComment.attr("abs:href"));
                commentsData.setAuthorUrl(name.attr("abs:href"));
                commentsData.setAuthor(name.text());
                commentsData.setComment(message.text());
                commentsData.setLevel(1);
                commentsData.setScore("");

                data.add(commentsData);
            }
        }
    } catch (IOException e) {
    }

    return data;
}

From source file:net.meiolania.apps.habrahabr.fragments.qa.loader.QaLoader.java

@Override
public ArrayList<QaData> loadInBackground() {
    ArrayList<QaData> data = new ArrayList<QaData>();

    try {/* w w  w.  jav a2 s  .  c o  m*/
        String readyUrl = url.replace("%page%", String.valueOf(page));

        Log.i(TAG, "Loading a page: " + readyUrl);

        Document document = Jsoup.connect(readyUrl).get();

        Elements qaList = document.select("div.post");

        for (Element qa : qaList) {
            QaData qaData = new QaData();

            Element title = qa.select("a.post_title").first();
            Element hubs = qa.select("div.hubs").first();
            Element answers = qa.select("div.informative").first();
            Element date = qa.select("div.published").first();
            Element author = qa.select("div.author > a").first();
            Element score = qa.select("span.score").first();

            qaData.setTitle(title.text());
            qaData.setUrl(title.attr("abs:href"));
            qaData.setHubs(hubs.text());
            qaData.setAnswers(answers.text());
            qaData.setDate(date.text());
            qaData.setAuthor(author.text());
            qaData.setScore(score.text());

            data.add(qaData);
        }
    } catch (IOException e) {
    }

    return data;
}

From source file:net.meiolania.apps.habrahabr.fragments.qa.loader.QaShowLoader.java

@Override
public QaFullData loadInBackground() {
    QaFullData data = new QaFullData();

    try {/*w w w  .  java 2 s.  c  om*/
        Log.i(TAG, "Loading a page: " + url);

        Document document = Jsoup.connect(url).get();

        Element title = document.select("span.post_title").first();
        Element hubs = document.select("div.hubs").first();
        Element content = document.select("div.content").first();
        Element tags = document.select("ul.tags").first();
        Element date = document.select("div.published").first();
        Element author = document.select("div.author > a").first();
        Element answers = document.select("span#comments_count").first();

        data.setTitle(title.text());
        data.setHubs(hubs.text());
        data.setContent(content.html());
        data.setTags(tags.text());
        data.setDate(date.text());
        data.setAuthor(author.text());
        data.setAnswers(answers.text());
    } catch (IOException e) {
    }

    return data;
}

From source file:net.meiolania.apps.habrahabr.fragments.users.loader.UsersLoader.java

@Override
public ArrayList<UsersData> loadInBackground() {
    ArrayList<UsersData> data = new ArrayList<UsersData>();

    try {// w  w w.j a v  a  2s .  c om
        Log.i(TAG, "Loading a page: " + url);

        Document document = Jsoup.connect(url).get();
        Elements users = document.select("div.user");

        for (Element user : users) {
            UsersData usersData = new UsersData();

            Element rating = user.select("div.rating").first();
            Element karma = user.select("div.karma").first();
            Element avatar = user.select("div.avatar > a > img").first();
            Element name = user.select("div.userlogin > div.username > a").first();
            Element lifetime = user.select("div.info > div.lifetime").first();

            usersData.setName(name.text());
            usersData.setUrl(name.attr("abs:href"));
            usersData.setRating(rating.text());
            usersData.setKarma(karma.text());
            usersData.setAvatar(avatar.attr("src"));
            usersData.setLifetime(lifetime.text());

            data.add(usersData);
        }
    } catch (IOException e) {
    }

    return data;
}

From source file:net.meiolania.apps.habrahabr.fragments.users.loader.UsersShowLoader.java

@Override
public UsersFullData loadInBackground() {
    UsersFullData data = new UsersFullData();

    try {/*from w w w .  ja v  a  2s  . c om*/
        Log.i(TAG, "Loading a page: " + url);

        Document document = Jsoup.connect(url).get();

        Element avatar = document.select("a.avatar > img").first();
        Element karma = document.select("div.karma > div.score > div.num").first();
        Element rating = document.select("div.rating > div.num").first();
        Element birthday = document.select("dd.bday").first();
        Element fullname = document.select("div.fullname").first();
        Element summary = document.select("dd.summary").first();
        Element interests = document.select("dl.interests > dd").first();

        data.setAvatar(avatar.attr("src"));
        data.setKarma(karma.text());
        data.setRating(rating.text());
        data.setBirthday(birthday != null ? birthday.text() : "");
        data.setFullname(fullname != null ? fullname.text() : "");
        data.setSummary(summary != null ? summary.text() : "");
        data.setInterests(interests != null ? interests.text() : "");
    } catch (IOException e) {
    }

    return data;
}

From source file:net.trustie.model.OpenHubProject_Model.java

public void afterProcess(Page page) {

    this.urlMd5 = DigestUtils.md5Hex(page.getPageUrl());
    SimpleDateFormat bartDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    this.collectTime = bartDateFormat.format(new Date());

    Document doc = page.getHtml().getDocument();

    // use_count//from w  w  w  .  j  a v a  2s . co  m
    Elements useCountLabel = doc
            .select("div#widgets div[itemprop=interactionCount] div.float_right div.use_count a");
    if (useCountLabel.size() > 0) {
        String strUseCount = useCountLabel.get(0).text();
        this.useCount = Integer.parseInt(StringUtils.remove(strUseCount, ','));
    }

    // tags
    Elements tags = doc.select("div#project_tags p a");
    String tag = null;
    List<String> listTags = new ArrayList<String>();
    for (Element e : tags) {
        tag = e.text();
        listTags.add(tag);
    }
    this.tags = StringHandler.combineTags(listTags);

    // quick reference
    // Elements quickRefs = doc.select("div.span6 div.well dl.");
    Elements quickRefs = doc.select("div.span6 div.well dl");
    if (quickRefs.size() > 0) {
        Element quickRef = quickRefs.get(0);
        handleQuickRef(quickRef);
    }

    // nutshell
    //      if (codeInfos.size() > 0) {
    //         String nutShell0 = codeInfos.get(0);
    //         handleNutShell0(nutShell0);
    //         String nutShell1 = codeInfos.get(1);
    //         handleNutShell1(nutShell1);
    //         String nutShell2 = codeInfos.get(2);
    //         handleNutShell2(nutShell2);
    //         String nutShell3 = codeInfos.get(3);
    //         handleNutShell3(nutShell3, page.getTime());
    //      }

    int tmplength = codeInfos.size();
    if (tmplength > 0) {
        if (tmplength == 1) {
            String nutShell0 = codeInfos.get(0);
            handleNutShell0(nutShell0);
        } else if (tmplength == 2) {
            String nutShell0 = codeInfos.get(0);
            handleNutShell0(nutShell0);
            String nutShell1 = codeInfos.get(1);
            handleNutShell1(nutShell1);
        } else if (tmplength == 3) {
            String nutShell0 = codeInfos.get(0);
            handleNutShell0(nutShell0);
            String nutShell1 = codeInfos.get(1);
            handleNutShell1(nutShell1);
            String nutShell2 = codeInfos.get(2);
            handleNutShell2(nutShell2);
        } else {
            String nutShell0 = codeInfos.get(0);
            handleNutShell0(nutShell0);
            String nutShell1 = codeInfos.get(1);
            handleNutShell1(nutShell1);
            String nutShell2 = codeInfos.get(2);
            handleNutShell2(nutShell2);
            String nutShell3 = codeInfos.get(3);
            handleNutShell3(nutShell3, page.getTime());
        }
    }

    List<String> eList = new ArrayList<String>();
    List<String> valueList = new ArrayList<String>();
    // language
    for (int i = 0; i < languages.size(); i++) {
        Element e = Jsoup.parse(languages.get(i));
        Element eValue = Jsoup.parse(percentages.get(i));
        // String strE = e.text();
        eList.add(e.text());
        // String strValue = eValue.text();
        valueList.add(eValue.text());
    }
    this.languagePercentages = StringHandler.assemblyOSSEANMap(eList, valueList);

    // activity
    String strtmp1 = "";
    String strtmp2 = "";
    String strtmp3 = "";
    String strtmp4 = "";
    // this.dCommitNumber = Integer.parseInt(dayActivityInfos.get(0));
    // this.dContributorNumber = Integer.parseInt(dayActivityInfos.get(1));
    //      if (dayActivityInfos.size() > 0) {
    //         strtmp1 = dayActivityInfos.get(0);
    //         this.daysCommitNumber = getInt(strtmp1);
    //         strtmp2 = dayActivityInfos.get(1);
    //         this.daysContributorNumber = getInt(strtmp2);
    //         strtmp3 = monthActivityInfos.get(0);
    //         this.monthsCommitNumber = getInt(strtmp3);
    //         strtmp4 = monthActivityInfos.get(1);
    //         this.monthsContributorNumber = getInt(strtmp4);
    //
    //      }

    int length = dayActivityInfos.size();
    if (length > 0) {
        if (length == 1) {
            strtmp1 = dayActivityInfos.get(0);
            this.daysCommitNumber = getInt(strtmp1);
        } else {
            strtmp1 = dayActivityInfos.get(0);
            this.daysCommitNumber = getInt(strtmp1);
            strtmp2 = dayActivityInfos.get(1);
            this.daysContributorNumber = getInt(strtmp2);
        }
    }

    int length1 = monthActivityInfos.size();
    if (length1 > 0) {
        if (length1 == 1) {
            strtmp3 = monthActivityInfos.get(0);
            this.monthsCommitNumber = getInt(strtmp3);
        } else {
            strtmp3 = monthActivityInfos.get(0);
            this.monthsCommitNumber = getInt(strtmp3);
            strtmp4 = monthActivityInfos.get(1);
            this.monthsContributorNumber = getInt(strtmp4);
        }
    }

    this.newContriNum = getInt(this.newContributor);
    //      this.theCommitTrend = allTrend.get(0);
    //      this.theContriTrend = allTrend.get(1);

    if (allTrend.size() > 0) {
        if (allTrend.size() == 1) {
            this.theCommitTrend = allTrend.get(0);
        } else {
            this.theCommitTrend = allTrend.get(0);
            this.theContriTrend = allTrend.get(1);
        }
    }

    // community
    // this.rateNum = getInt(this.rateInfo);
    this.ReContributor = StringHandler.combineTags(this.RecenctContributors);
    // button informations
    //      String headHref = "https://www.openhub.net";
    //      Document docTmp = Jsoup.parse(this.linkInfos.get(0));
    //      this.links = docTmp.getElementsByTag("a");
    //      
    //      for(Element link : links){
    //         String url = headHref + link.attr("href");
    //         ansTmp += url +"**";
    //      }
    //      

    //      if (this.firstLinks.size() > 0) {
    //
    //         this.newsLink = tmphref + this.firstLinks.get(0);
    //         this.langLink = tmphref + this.firstLinks.get(1);
    //
    //         this.commitsLink = tmphref + this.firstLinks.get(2);
    //         this.settingLink = tmphref + this.otherLinks.get(0);
    //         
    //         this.sharingwidgetsLink = tmphref + this.otherLinks.get(1);
    //         this.relatedprojectsLink = tmphref + this.otherLinks.get(2);
    //         this.costestLink = tmphref + this.otherLinks.get(3);
    //         this.contributorLink = tmphref + this.otherLinks.get(4);
    //      }

    this.rateInfo = this.rateInfo.trim();
    this.rateLevel = this.rateLevel.trim();
    //?projectlinks??
    this.projectLinks = this.projectLinks.trim();
    if (this.projectLinks.contains("")) {
        this.projectLinks = this.projectLinks.replace("", " ");
        this.projectLinks = this.projectLinks.trim();
    }
    this.activity = this.activity.trim();

    SimpleDateFormat s = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    this.crawlerTime = s.format(page.getTime());
    this.projectUrl = page.getPageUrl();

}

From source file:net.trustie.model.OpenHubProject_Model.java

private void handleQuickRef(Element quickRef) {
    Elements itemNames = quickRef.select("dt");
    Elements itemValues = quickRef.select("dd");
    Element e = null;
    Element eValue = null;//from   w  w  w.j  a  v  a 2  s . c  o  m
    for (int i = 0; i < itemNames.size(); i++) {
        e = itemNames.get(i);
        eValue = itemValues.get(i);
        String refName = e.text();
        switch (refName) {
        case "Organization:": {
            this.organization = eValue.text();
            break;
        }
        case "Project Links:": {
            Elements links = eValue.select("a");
            String[] tmp = new String[links.size()];
            Element ele = null;
            for (int j = 0; j < links.size(); j++) {
                ele = links.get(j);
                tmp[j] = ele.text() + Seperator.SOURCE_SEPERATOR + ele.attr("href");
            }
            this.projectLinks = StringUtils.join(tmp, Seperator.OSSEAN_SEPERATOR);
            break;
        }
        case "Code Locations:": {
            Elements locs = eValue.select("a");
            if (locs.size() == 0) {
                this.codeLocation = eValue.text();
            } else {
                Element link = locs.get(0);
                this.codeLocation = link.text() + Seperator.SOURCE_SEPERATOR + link.attr("href");
            }

            break;
        }
        case "Licenses:": {
            Elements links = eValue.select("a");
            List<String> listLicenses = new ArrayList<String>();
            // String[] tmp = new String[links.size()];
            for (int j = 0; j < links.size(); j++) {
                listLicenses.add(links.get(j).text());
                // tmp[j] = links.get(j).text();
            }
            this.licenses = StringHandler.combineTags(listLicenses);
            break;
        }
        case "Similar Projects:": {
            // System.out.println(eValue);
            Elements projects = eValue.select("td[width=49%]");
            // System.out.println(projects.size());
            String[] tmp = new String[projects.size()];
            Element ele = null;
            for (int j = 0; j < projects.size(); j++) {
                ele = projects.get(j);
                Element project = ele.select("a").get(0);
                tmp[j] = project.text() + Seperator.SOURCE_SEPERATOR + project.attr("href");
            }
            this.similarProjects = StringUtils.join(tmp, Seperator.OSSEAN_SEPERATOR);
            break;
        }
        case "Managers:": {
            if ("Become the first manager for BugSystem".equals(eValue.text())) {
                break;
            }
            Elements users = eValue.select("a");
            String[] tmp = new String[users.size()];
            Element ele = null;
            for (int j = 0; j < users.size(); j++) {
                ele = users.get(j);
                tmp[j] = ele.text() + Seperator.SOURCE_SEPERATOR + ele.attr("href");
            }
            this.managers = StringUtils.join(tmp, Seperator.OSSEAN_SEPERATOR);
            break;
        }
        default: {
            break;
        }
        }
    }
}

From source file:net.trustie.model.OpenHubProject_Model.java

private void handleNutShell0(String nutshell) {
    Elements eles = getAElements(nutshell);
    Element ele = null;
    ele = eles.get(0);/*w ww.  j av a  2s  .co m*/
    this.commitNum = getInt(ele.text());
    ele = eles.get(1);
    this.contributorNum = getInt(ele.text());
    ele = eles.get(2);
    this.codeLinesNum = getInt(ele.text());
}