Java Code Examples for org.jsoup.select.Elements.select()

The following are Jave code examples for showing how to use select() of the org.jsoup.select.Elements class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: PicKing   File: RosiMM.java   Source Code and License Vote up 7 votes
@Override
public Map<ContentsActivity.parameter, Object> getContent(String baseUrl, String currentUrl, byte[] result, Map<ContentsActivity.parameter, Object> resultMap) throws UnsupportedEncodingException {
    List<AlbumInfo> urls = new ArrayList<>();
    Document document = Jsoup.parse(new String(result, "gbk"));
    Elements elements = document.select("#sliding li");
    for (Element element : elements) {
        AlbumInfo temp = new AlbumInfo();

        Elements title = element.select(".p-title");
        if (title.size() > 0)
            temp.setTitle(title.get(0).text());

        Elements album = element.select("a:has(img)");
        temp.setAlbumUrl(baseUrl + album.attr("href"));
        Elements pic = album.select("img");
        if (pic.size() > 0)
            temp.setPicUrl(pic.get(0).attr("src"));
        urls.add(temp);
    }
    resultMap.put(ContentsActivity.parameter.CURRENT_URL, currentUrl);
    resultMap.put(ContentsActivity.parameter.RESULT, urls);
    return resultMap;
}
 
Example 2
Project: jspider   File: PagingRequestFactorySample.java   Source Code and License Vote up 6 votes
@Override
public Result process(Request request, Page page) {
    Result result = new Result();

    Elements elements = page.document().select("div.mainPanel table.table tr");

    List<Map> list = new ArrayList<Map>();
    for (Element element : elements) {
        Elements tdElements = elements.select("td");
        if (tdElements.size() > 5) {
            Map<String, String> info = new HashMap<String, String>();

            info.put("ip", tdElements.get(0).text());
            info.put("port", tdElements.get(1).text());
            info.put("country", tdElements.get(2).text());
            info.put("anonymous", tdElements.get(3).text());
            info.put("type", tdElements.get(4).text());

            list.add(info);
        }
    }

    result.put("list", list);
    return result;
}
 
Example 3
Project: jspider   File: URLTemplateRequestFactorySample.java   Source Code and License Vote up 6 votes
@Override
public Result process(Request request, Page page) {
    Result result = new Result();

    Elements elements = page.document().select("div.mainPanel table.table tr");

    List<Map> list = new ArrayList<Map>();
    for (Element element : elements) {
        Elements tdElements = elements.select("td");
        if (tdElements.size() > 5) {
            Map<String, String> info = new HashMap<String, String>();

            info.put("ip", tdElements.get(0).text());
            info.put("port", tdElements.get(1).text());
            info.put("country", tdElements.get(2).text());
            info.put("anonymous", tdElements.get(3).text());
            info.put("type", tdElements.get(4).text());

            list.add(info);
        }
    }

    result.put("list", list);
    return result;
}
 
Example 4
Project: Idea-Plagiarism   File: Thesaurus.java   Source Code and License Vote up 6 votes
public HashMap<String, ArrayList<String>> getSynonyms() throws IOException, InterruptedException {
    if (synonyms.isEmpty()) {
        for (String word : wordList) {
            try {
                Document doc = Jsoup.connect("http://www.thesaurus.com/browse/" + word)
                        .userAgent("Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0")
                        .timeout(3000)
                        .get();
                Elements block = doc.getElementsByClass("relevancy-block");
                Elements list = block.select(".relevancy-list");
                Elements text = list.select(".text");
                ArrayList<String> synonymList = new ArrayList<>();
                for (int j = 0; j < text.size(); j++) {
                    synonymList.add(text.get(j).text());
                }
                synonyms.put(word, synonymList);
            } catch (IOException e) {
            }
        }
    }
    return synonyms;
}
 
Example 5
Project: libris   File: URLGoogleImageSearcher.java   Source Code and License Vote up 6 votes
private ArrayList<String> retrieveSimilarImageFromHTML(Elements body) {
    ArrayList<String> imageRes = new ArrayList<String>();
    Elements images = body.select("div.rg_meta");

    Gson gson = new Gson();
    JsonObject jsImage;
    String imageUrl;
    for (Element image : images){

        jsImage = gson.fromJson(image.text(), JsonObject.class);
        imageUrl = jsImage.get("ou").getAsString();
        try {
            new URL(imageUrl);
            imageRes.add(imageUrl);
        } catch (MalformedURLException e) {
            printMalformedError(e);
        }
    }
    return imageRes;
}
 
Example 6
Project: PicKing   File: XiuMM.java   Source Code and License Vote up 6 votes
@Override
public Map<ContentsActivity.parameter, Object> getContent(String baseUrl, String currentUrl, byte[] result, Map<ContentsActivity.parameter, Object> resultMap) throws UnsupportedEncodingException {
    List<AlbumInfo> urls = new ArrayList<>();
    Document document = Jsoup.parse(new String(result, "utf-8"));
    Elements elements = document.select("div.album");
    for (Element element : elements) {
        AlbumInfo temp = new AlbumInfo();

        Elements title = element.select("span.name");
        if (title.size() > 0)
            temp.setTitle(title.get(0).text());

        Elements album = element.select(".pic_box a");
        temp.setAlbumUrl(album.attr("href"));
        Elements pic = album.select("img");
        if (pic.size() > 0)
            temp.setPicUrl(pic.get(0).attr("src"));
        urls.add(temp);
    }
    resultMap.put(ContentsActivity.parameter.CURRENT_URL, currentUrl);
    resultMap.put(ContentsActivity.parameter.RESULT, urls);
    return resultMap;
}
 
Example 7
Project: PicKing   File: AoJiao.java   Source Code and License Vote up 6 votes
@Override
public Map<ContentsActivity.parameter, Object> getContent(String baseUrl, String currentUrl, byte[] result, Map<ContentsActivity.parameter, Object> resultMap) throws UnsupportedEncodingException {
    List<AlbumInfo> data = new ArrayList<>();
    Document document = Jsoup.parse(new String(result, "utf-8"));
    Elements elements = document.select("section");
    for (Element element : elements) {
        AlbumInfo temp = new AlbumInfo();

        Elements album = element.select("a:has(img)");
        if (album.size() > 0) {
            temp.setAlbumUrl(album.attr("href"));
            Elements pic = album.select("img");
            if (pic.size() > 0)
                temp.setPicUrl(pic.get(0).attr("data-src"));
        }

        data.add(temp);
    }

    resultMap.put(ContentsActivity.parameter.CURRENT_URL, currentUrl);
    resultMap.put(ContentsActivity.parameter.RESULT, data);
    return resultMap;
}
 
Example 8
Project: libris   File: URLGoogleImageSearcher.java   Source Code and License Vote up 5 votes
private ArrayList<String> retrieveDescriptionFromHTML(Elements body) {
    ArrayList<String> descRes = new ArrayList<String>();
    Elements descriptions = body.select("span.st");

    for (Element desc : descriptions)
        descRes.add(desc.text());

    return descRes;
}
 
Example 9
Project: guanggoo-android   File: GetUserProfileTask.java   Source Code and License Vote up 5 votes
@Override
public void run() {
    Document doc;

    try {
        doc = get(mUrl);
    } catch (IOException e) {
        e.printStackTrace();
        failedOnUI(e.getMessage());
        return;
    }

    Elements userProfileElements = doc.select("div.user-page .profile");
    if (userProfileElements.isEmpty()) {
        failedOnUI("获取用户资料失败");
        return;
    }

    Elements headerElements = userProfileElements.select("div.ui-header");
    if (headerElements.isEmpty()) {
        failedOnUI("获取用户资料失败");
        return;
    }

    UserProfile profile = new UserProfile();

    profile.setUrl(mUrl);
    profile.setAvatar(headerElements.select("img.avatar").attr("src"));
    profile.setUsername(headerElements.select("div.username").text());
    profile.setNumber(headerElements.select("div.user-number .number").text());
    profile.setSince(headerElements.select("div.user-number .since").text());

    if (profile.isValid()) {
        successOnUI(profile);
    } else {
        failedOnUI("获取用户资料出错");
    }
}
 
Example 10
Project: guanggoo-android   File: GetCommentsTask.java   Source Code and License Vote up 5 votes
public static Map<Integer, Comment> getCommentsFromElements(Elements elements) {
    TreeMap<Integer, Comment> comments = new TreeMap<>();

    Elements replyItems = elements.select("div.reply-item");

    for (Element replyItem : replyItems) {
        Comment comment = getCommentFromElement(replyItem);
        comments.put(comment.getMeta().getFloor(), comment);
    }

    return comments.descendingMap();
}
 
Example 11
Project: JsoupSample   File: JsoupPtFictionHomeManager.java   Source Code and License Vote up 5 votes
private void setData(List<FictionModel> list, int eq, String type) {
    Elements select = document.select("div.blockcontent").eq(eq);
    Elements itemElements = select.select("li");
    list.add(getMoreTitle(type, select));
    FictionModel fictionModel;
    for (Element element : itemElements) {
        fictionModel = new FictionModel();
        Elements a = element.select("a");
        fictionModel.title = a.text();
        fictionModel.detailUrl = a.attr("abs:href");
        fictionModel.type = TYPE_ITEM;
        list.add(fictionModel);
    }
}
 
Example 12
Project: md-stepper   File: Step.java   Source Code and License Vote up 5 votes
private void readStepContent(Elements elements) {
  Elements contentElements = elements.select(DESIGN_TAG_CONTENT);
  if (!contentElements.isEmpty()) {
    Element contentElement = contentElements.get(0);
    Elements children = contentElement.children();

    if (children.size() > 1) {
      String msg = "Only one child allowed for tag <" + DESIGN_TAG_CONTENT + ">";
      throw new IllegalArgumentException(msg);
    }

    Component component = designContext.readDesign(children.first());
    setContent(component);
  }
}
 
Example 13
Project: PicKing   File: Meizi4493.java   Source Code and License Vote up 5 votes
@Override
public Map<ContentsActivity.parameter, Object> getContent(String baseUrl, String currentUrl, byte[] result, Map<ContentsActivity.parameter, Object> resultMap) throws UnsupportedEncodingException {
    List<AlbumInfo> urls = new ArrayList<>();
    Document document = Jsoup.parse(new String(result, "gb2312"));
    Elements elements = document.select(".piclist li");
    for (Element element : elements) {
        AlbumInfo temp = new AlbumInfo();

        Elements title = element.select("a:has(img) span");
        if (title.size() > 0)
            temp.setTitle(title.get(0).text());

        Elements time = element.select(".b1");
        if (time.size() > 0)
            temp.setTime(time.get(0).text());

        Elements album = element.select("a:has(img)");
        temp.setAlbumUrl(baseUrl + album.attr("href"));
        Elements pic = album.select("img");
        if (pic.size() > 0)
            temp.setPicUrl(pic.get(0).attr("src"));
        urls.add(temp);
    }
    resultMap.put(ContentsActivity.parameter.CURRENT_URL, currentUrl);
    resultMap.put(ContentsActivity.parameter.RESULT, urls);
    return resultMap;
}
 
Example 14
Project: libris   File: URLGoogleImageSearcher.java   Source Code and License Vote up 5 votes
private ArrayList<String> retrieveTitleFromHTML(Elements body) {
    ArrayList<String> titleRes = new ArrayList<String>();
    Elements titles = body.select("h3.r");

    for (Element title : titles)
        titleRes.add(title.text());

    return titleRes;
}
 
Example 15
Project: PicKing   File: Acg12.java   Source Code and License Vote up 5 votes
@Override
public Map<ContentsActivity.parameter, Object> getContent(String baseUrl, String currentUrl, byte[] result, Map<ContentsActivity.parameter, Object> resultMap) throws UnsupportedEncodingException {
    List<AlbumInfo> data = new ArrayList<>();
    Document document = Jsoup.parse(new String(result, "utf-8"));
    Elements elements = document.select("section");
    for (Element element : elements) {
        AlbumInfo temp = new AlbumInfo();

        Elements album = element.select(".card-bg > a:has(img)");
        if (album.size() > 0) {
            temp.setAlbumUrl(album.attr("href"));
            Elements pic = album.select("img");
            if (pic.size() > 0) {
                Log.e("Acg12", "getContent: " + pic.get(0).attr("data-src"));
                temp.setPicUrl(pic.get(0).attr("data-src"));
            }
        }

        Elements title = element.select("h3.title");
        if (title.size() > 0)
            temp.setTitle(title.get(0).text());

        Elements time = element.select("time");
        if (time.size() > 0)
            temp.setTime(time.attr("title") + " " + time.text());

        data.add(temp);
    }

    resultMap.put(ContentsActivity.parameter.CURRENT_URL, currentUrl);
    resultMap.put(ContentsActivity.parameter.RESULT, data);
    return resultMap;
}
 
Example 16
Project: libris   File: URLGoogleImageSearcher.java   Source Code and License Vote up 4 votes
private String retrieveBestGuessFromHTML(Elements body) {
    String bestGuessRes;
    Elements bestGuesses = body.select("a._gUb");
    bestGuessRes = bestGuesses.first().text();
    return bestGuessRes;
}
 
Example 17
Project: guanggoo-android   File: GetTopicDetailTask.java   Source Code and License Vote up 4 votes
@Override
public void run() {
    Document doc;

    try {
        doc = get(mUrl);
    } catch (IOException e) {
        e.printStackTrace();
        failedOnUI(e.getMessage());
        return;
    }

    Elements topicDetailElements = doc.select("div.topic-detail");

    if (topicDetailElements.isEmpty()) {
        failedOnUI("找不到主题详情");
        return;
    }

    Elements elements = topicDetailElements.select("div.ui-header");

    if (elements.isEmpty()) {
        failedOnUI("找不到主题元信息");
        return;
    }

    TopicDetail topicDetail = new TopicDetail();

    Topic topic = GetTopicListTask.createTopicFromElement(elements.first());

    topicDetail.setTopic(topic);
    // 解析收藏
    Elements favouriteElement = doc.select(".J_topicFavorite");
    if(favouriteElement!=null){
        String hrefUrl = favouriteElement.attr("href");
        String dataType = favouriteElement.attr("data-type");
        String text = favouriteElement.text();
        Favorite favorite = new Favorite();
        favorite.setUrl(hrefUrl);
        favorite.setDataType(dataType);
        favorite.setText(text);
        topicDetail.setFavorite(favorite);
    }

    elements = topicDetailElements.select("div.ui-content");

    if (elements.isEmpty()) {
        failedOnUI("找不到主题内容");
        return;
    }

    topicDetail.setContent(elements.first().outerHtml());

    Elements commentsElements = doc.select("div.topic-reply");

    Map<Integer, Comment> comments = GetCommentsTask.getCommentsFromElements(commentsElements);

    topicDetail.setComments(comments);

    successOnUI(topicDetail);
}
 
Example 18
Project: guanggoo-android   File: GetReplyListTask.java   Source Code and License Vote up 4 votes
@Override
public void run() {
    List<Reply> replies = new ArrayList<>();

    boolean succeed = false;
    boolean hasMore = false;

    try {
        Document doc = get(mUrl);

        Elements elements = doc.select("div.reply-item");

        for (Element element : elements) {
            Reply reply = new Reply();

            Elements topicElements = element.select("span.title a");
            if (topicElements.isEmpty()) {
                continue;
            }

            Topic topic = new Topic();
            topic.setTitle(topicElements.first().text());
            topic.setUrl(topicElements.first().absUrl("href"));

            reply.setTopic(topic);

            Elements contentElements = element.select("div.content");
            if (contentElements.isEmpty()) {
                continue;
            }

            reply.setContent(contentElements.outerHtml());

            replies.add(reply);
        }

        succeed = true;

        Elements paginationElements = doc.select("ul.pagination");
        if (!paginationElements.isEmpty()) {
            Elements disabledElements = paginationElements.select("li.disabled");
            if (disabledElements.isEmpty()) {
                hasMore = true;
            } else if (disabledElements.last() != null) {
                Elements disableLinkElements = disabledElements.last().select("a");
                if (!ConstantUtil.NEXT_PAGE.equals(disableLinkElements.text())) {
                    hasMore = true;
                }
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

    if (succeed) {
        ReplyList replyList = new ReplyList();
        replyList.setReplies(replies);
        replyList.setHasMore(hasMore);
        successOnUI(replyList);
    } else {
        failedOnUI("获取回复列表失败");
    }
}
 
Example 19
Project: guanggoo-android   File: GetTopicListTask.java   Source Code and License Vote up 4 votes
@Override
public void run() {
    List<Topic> topics = new ArrayList<>();

    boolean succeed = false;
    boolean hasMore = false;
    try {
        Document doc = get(mUrl);

        Elements elements = doc.select("div.topic-item");

        for (Element element : elements) {
            Topic topic = createTopicFromElement(element);
            topics.add(topic);
        }

        succeed = true;

        Elements paginationElements = doc.select("ul.pagination");
        if (!paginationElements.isEmpty()) {
            Elements disabledElements = paginationElements.select("li.disabled");
            if (disabledElements.isEmpty()) {
                hasMore = true;
            } else if (disabledElements.last() != null) {
                Elements disableLinkElements = disabledElements.last().select("a");
                if (!ConstantUtil.NEXT_PAGE.equals(disableLinkElements.text())) {
                    hasMore = true;
                }
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

    if (succeed) {
        TopicList topicList = new TopicList();
        topicList.setTopics(topics);
        topicList.setHasMore(hasMore);
        successOnUI(topicList);
    } else {
        failedOnUI("获取主题列表失败");
    }
}
 
Example 20
Project: PicKing   File: Apic.java   Source Code and License Vote up 4 votes
@Override
public Map<ContentsActivity.parameter, Object> getContent(String baseUrl, String currentUrl, byte[] result, Map<ContentsActivity.parameter, Object> resultMap) throws UnsupportedEncodingException {
    List<AlbumInfo> data = new ArrayList<>();
    Document document = Jsoup.parse(new String(result, "utf-8"));
    Log.e("Apic", "getContent: " + document.html());

    Elements elements = document.select("div.loop");
    for (Element element : elements) {
        AlbumInfo temp = new AlbumInfo();
        Elements album = element.select(".content a:has(img)");
        if (album.size() > 0)
            temp.setAlbumUrl(album.attr("href") + "/1");

        Elements pic = album.select("img");
        if (pic.size() > 0)
            temp.setPicUrl(pic.get(0).attr("src").trim());

        Elements title = element.select("h2 a");
        if (title.size() > 0)
            temp.setTitle(title.get(0).attr("title"));

        Elements time = element.select(".date");
        if (time.size() > 0)
            temp.setTime(time.get(0).text());

        data.add(temp);
    }

    /*if (data.size() == 0) {
        Elements elements1 = document.select(".postlists article a.block-image");
        Log.e("Apic", "getContent: " + elements1.html());
        for (Element element : elements1) {
            AlbumInfo temp = new AlbumInfo();
            temp.setAlbumUrl(element.attr("href").trim());
            String s = element.attr("style");
            Pattern pattern = Pattern.compile("http.*jpg");
            Matcher matcher = pattern.matcher(s);
            if (matcher.find())
                temp.setPicUrl(matcher.group());
            data.add(temp);
        }
    }*/

    resultMap.put(ContentsActivity.parameter.CURRENT_URL, currentUrl);
    resultMap.put(ContentsActivity.parameter.RESULT, data);
    return resultMap;
}