Java Code Examples for org.jsoup.nodes.Element#hasClass()

The following examples show how to use org.jsoup.nodes.Element#hasClass() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EroShareRipper.java    From ripme with MIT License 5 votes vote down vote up
public static List<URL> getURLs(URL url) throws IOException{

        Response resp = Http.url(url)
                            .ignoreContentType()
                            .response();

        Document doc = resp.parse();

        List<URL> URLs = new ArrayList<>();
        //Pictures
        Elements imgs = doc.getElementsByTag("img");
        for (Element img : imgs) {
            if (img.hasClass("album-image")) {
                String imageURL = img.attr("src");
                URLs.add(new URL(imageURL));
            }
        }
        //Videos
        Elements vids = doc.getElementsByTag("video");
        for (Element vid : vids) {
            if (vid.hasClass("album-video")) {
                Elements source = vid.getElementsByTag("source");
                String videoURL = source.first().attr("src");
                URLs.add(new URL(videoURL));
            }
        }

        return URLs;
    }
 
Example 2
Source File: EpgCrawler.java    From MyTv with Apache License 2.0 5 votes vote down vote up
/**
 * 解析电视节目表
 * 
 * @param html
 * @return
 */
private List<ProgramTable> parseProgramTable(String html) {
	Document doc = Jsoup.parse(html);
	List<ProgramTable> resultList = new ArrayList<ProgramTable>();
	Elements channelElements = doc.select("#channelTitle");
	String stationName = channelElements.get(0).text().trim();
	Elements weekElements = doc.select("#week li[rel]");
	int week = 0;
	String date = null;
	for (int i = 0, size = weekElements == null ? 0 : weekElements.size(); i < size; i++) {
		Element element = weekElements.get(i);
		if (element.hasClass("cur")) {
			week = i + 1;
			date = element.attr("rel").trim();
			break;
		}
	}
	Elements programElemens = doc.select("#epg_list div.content_c dl dd")
			.select("a.p_name_a, a.p_name");
	for (int i = 0, size = programElemens == null ? 0 : programElemens
			.size(); i < size; i++) {
		Element programElement = programElemens.get(i);
		String programContent = programElement.text().trim();
		String[] pc = programContent.split("\\s+");
		ProgramTable pt = new ProgramTable();
		pt.setAirDate(date);
		pt.setAirTime(date + " " + pc[0] + ":00");
		pt.setProgram(pc[1]);
		pt.setStationName(stationName);
		pt.setWeek(week);
		for (CrawlEventListener listener : listeners) {
			listener.itemFound(new ProgramTableFoundEvent(this, pt));
		}
		resultList.add(pt);
	}
	return resultList;
}
 
Example 3
Source File: LoadGiveawayDetailsTask.java    From SteamGifts with MIT License 5 votes vote down vote up
private Giveaway loadGiveaway(Document document, Uri linkUri) {
    Element element = document.select(".featured__inner-wrap").first();

    // Basic information
    if (linkUri.getPathSegments().size() < 3)
        throw new IllegalStateException("Too few path segments. " + linkUri.getPath());
    String giveawayLink = linkUri.getPathSegments().get(1);
    String giveawayName = linkUri.getPathSegments().get(2);

    Giveaway giveaway = new Giveaway(giveawayLink);
    giveaway.setTitle(Utils.getPageTitle(document));
    giveaway.setName(giveawayName);

    giveaway.setCreator(element.select(".featured__columns > div a").text());

    // Entries, would usually have comment count too... but we don't display that anywhere.
    Element sidebarElement = document.select("a.sidebar__navigation__item__link[href$=/entries] .sidebar__navigation__item__count").first();
    try {
        giveaway.setEntries(sidebarElement == null ? -1 : Utils.parseInt(sidebarElement.text()));
    } catch (NumberFormatException e) {
        if (sidebarElement != null)
            Log.w(TAG, "Unable to parse entry count: " + sidebarElement.text());

        giveaway.setEntries(0);
    }

    // this is overwritten by loadExtras()
    giveaway.setEntered(false);

    // More details
    Element icon = element.select(".global__image-outer-wrap--game-large").first();
    Uri uriIcon = icon.hasClass("global__image-outer-wrap--missing-image") ? null : Uri.parse(icon.attr("href"));

    Utils.loadGiveaway(giveaway, element, "featured", "featured__heading__small", uriIcon);
    return giveaway;
}
 
Example 4
Source File: Elements.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 Determine if any of the matched elements have this class name set in their {@code class} attribute.
 @param className class name to check for
 @return true if any do, false if none do
 */
public boolean hasClass(String className) {
    for (Element element : this) {
        if (element.hasClass(className))
            return true;
    }
    return false;
}
 
Example 5
Source File: Elements.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 Determine if any of the matched elements have this class name set in their {@code class} attribute.
 @param className class name to check for
 @return true if any do, false if none do
 */
public boolean hasClass(String className) {
    for (Element element : this) {
        if (element.hasClass(className))
            return true;
    }
    return false;
}
 
Example 6
Source File: Elements.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 Determine if any of the matched elements have this class name set in their {@code class} attribute.
 @param className class name to check for
 @return true if any do, false if none do
 */
public boolean hasClass(String className) {
    for (Element element : this) {
        if (element.hasClass(className))
            return true;
    }
    return false;
}
 
Example 7
Source File: Elements.java    From jsoup-learning with MIT License 5 votes vote down vote up
/**
 Determine if any of the matched elements have this class name set in their {@code class} attribute.
 @param className class name to check for
 @return true if any do, false if none do
 */
public boolean hasClass(String className) {
    for (Element element : contents) {
        if (element.hasClass(className))
            return true;
    }
    return false;
}
 
Example 8
Source File: NavBuilder.java    From rebuild with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 渲染导航菜單
 *
 * @param item
 * @param activeNav
 * @return
 */
public String renderNavItem(JSONObject item, String activeNav) {
    final boolean isUrlType = "URL".equals(item.getString("type"));
    String navName = item.getString("value");
    String navUrl = item.getString("value");

    boolean isOutUrl = isUrlType && navUrl.startsWith("http");
    if (isUrlType) {
        navName = "nav_url-" + navName.hashCode();
        if (isOutUrl) {
            navUrl = ServerListener.getContextPath() + "/commons/url-safe?url=" + CodecUtils.urlEncode(navUrl);
        } else {
            navUrl = ServerListener.getContextPath() + navUrl;
        }
    } else if (NAV_FEEDS.equals(navName)) {
        navName = "nav_entity-Feeds";
        navUrl = ServerListener.getContextPath() + "/feeds/home";
    } else if (NAV_FILEMRG.equals(navName)) {
        navName = "nav_entity-Attachment";
        navUrl = ServerListener.getContextPath() + "/files/home";
    } else {
        navName = "nav_entity-" + navName;
        navUrl = ServerListener.getContextPath() + "/app/" + navUrl + "/list";
    }

    String navIcon = StringUtils.defaultIfBlank(item.getString("icon"), "texture");
    String navText = item.getString("text");

    JSONArray subNavs = null;
    if (activeNav != null) {
        subNavs = item.getJSONArray("sub");
        if (subNavs == null || subNavs.isEmpty()) {
            subNavs = null;
        }
    }

    StringBuilder navHtml = new StringBuilder()
            .append(String.format("<li class=\"%s\"><a href=\"%s\" target=\"%s\"><i class=\"icon zmdi zmdi-%s\"></i><span>%s</span></a>",
                    navName + (subNavs == null ? StringUtils.EMPTY : " parent"),
                    subNavs == null ? navUrl : "###",
                    isOutUrl ? "_blank" : "_self",
                    navIcon,
                    navText));
    if (subNavs != null) {
        StringBuilder subHtml = new StringBuilder()
                .append("<ul class=\"sub-menu\"><li class=\"title\">")
                .append(navText)
                .append("</li><li class=\"nav-items\"><div class=\"content\"><ul class=\"sub-menu-ul\">");

        for (Object o : subNavs) {
            JSONObject subNav = (JSONObject) o;
            subHtml.append(renderNavItem(subNav, null));
        }
        subHtml.append("</ul></div></li></ul>");
        navHtml.append(subHtml);
    }
    navHtml.append("</li>");

    if (activeNav != null) {
        Document navBody = Jsoup.parseBodyFragment(navHtml.toString());
        for (Element nav : navBody.select("." + activeNav)) {
            nav.addClass("active");
            if (activeNav.startsWith("nav_entity-")) {
                Element navParent = nav.parent();
                if (navParent != null && navParent.hasClass("sub-menu-ul")) {
                    navParent.parent().parent().parent().parent().addClass("open active");
                }
            }
        }
        return navBody.selectFirst("li").outerHtml();
    }
    return navHtml.toString();
}
 
Example 9
Source File: MTGTop8DeckSniffer.java    From MtgDesktopCompanion with GNU General Public License v3.0 4 votes vote down vote up
@Override
public MagicDeck getDeck(RetrievableDeck info) throws IOException {
	Document root = URLTools.extractHtml(info.getUrl().toString());
	MagicDeck d = new MagicDeck();
	d.setDescription(info.getUrl().toString());
	d.setName(info.getName());

	Elements doc = root.select("table.Stable").get(1).select("td table").select(MTGConstants.HTML_TAG_TD);

	boolean side = false;
	for (Element e : doc.select("td table td")) {

		if (e.hasClass("O13")) {
			if (e.text().equalsIgnoreCase("SIDEBOARD"))
				side = true;
		} else {

			int qte = Integer.parseInt(e.text().substring(0, e.text().indexOf(' ')));
			String name = e.select("span.L14").text();
			if (!name.equals("")) 
			{
				try {
					
				MagicCard mc = MTGControler.getInstance().getEnabled(MTGCardsProvider.class).searchCardByName( name, null, true).get(0);
				if (!side)
					d.getMain().put(mc, qte);
				else
					d.getSideBoard().put(mc, qte);
				
				notify(mc);

				}
				catch(IndexOutOfBoundsException err)
				{
					logger.error("Error getting " + name,err);
				}
			}
		}

	}

	return d;
}
 
Example 10
Source File: MagicBazarShopper.java    From MtgDesktopCompanion with GNU General Public License v3.0 4 votes vote down vote up
private List<OrderEntry> parse(Document doc, String id, Date date) {
	List<OrderEntry> entries = new ArrayList<>();
	Elements table = doc.select("div.table div.tr");
	table.remove(0);
	
	
	for(int i=0;i<table.size();i++)
	{
		Element e = table.get(i);
		boolean iscard=e.hasClass("filterElement");
		String name = e.select("div.td.name").text();
		
		
		if(!name.isEmpty())
		{

			OrderEntry entrie = new OrderEntry();
				entrie.setIdTransation(id);
				entrie.setSource(getName());
				entrie.setCurrency(Currency.getInstance("EUR"));
				entrie.setSeller(getName());
				entrie.setTypeTransaction(TYPE_TRANSACTION.BUY);
				entrie.setTransactionDate(date);
				entrie.setDescription(name);
				if(iscard)
				{
					entrie.setType(TYPE_ITEM.CARD);
					entrie.setDescription(e.select("div.td.name.name_mobile").text());
					entrie.setItemPrice(UITools.parseDouble(e.attr("attribute_price")));
					String set = e.select("div.td.ext img").attr("title");
					try {
						
						entrie.setEdition(MTGControler.getInstance().getEnabled(MTGCardsProvider.class).getSetByName(set));
					}
					catch(Exception ex)
					{
						logger.error(set + " is not found");
					}
					
					
				}
				else
				{
					String price =e.select("div.new_price").html().replaceAll("&nbsp;"+Currency.getInstance("EUR").getSymbol(), "").trim(); 
					entrie.setItemPrice(UITools.parseDouble(price));
					if(entrie.getDescription().contains("Set")||entrie.getDescription().toLowerCase().contains("collection"))
						entrie.setType(TYPE_ITEM.FULLSET);
					else if(entrie.getDescription().toLowerCase().contains("booster"))
						entrie.setType(TYPE_ITEM.BOOSTER);
					else if(entrie.getDescription().toLowerCase().startsWith("boite de") || entrie.getDescription().contains("Display") )
						entrie.setType(TYPE_ITEM.BOX);
					else
						entrie.setType(TYPE_ITEM.LOTS);
				}
				notify(entrie);
				entries.add(entrie);	
		}
		
		
		
	}
	
	
	
	return entries;
}
 
Example 11
Source File: HiParser.java    From hipda with GNU General Public License v2.0 4 votes vote down vote up
public static SimpleListBean parseNotify(Document doc) {
    if (doc == null) {
        return null;
    }

    Elements feedES = doc.select("ul.feed");
    if (feedES.size() == 0) {
        return null;
    }

    SimpleListBean list = new SimpleListBean();
    Elements liES = feedES.first().select("li");
    for (int i = 0; i < liES.size(); ++i) {
        Element liE = liES.get(i);
        Elements divES = liE.select("div");
        if (divES.size() == 0) {
            continue;
        }
        SimpleListItemBean item = null;
        Element el = divES.first();
        if (el.hasClass("f_thread")) {
            // user reply your thread
            item = parseNotifyThread(el);
        } else if (el.hasClass("f_quote")) {
            // user quote your post
            item = parseNotifyQuoteAndReply(el);
        } else if (el.hasClass("f_reply")) {
            // user reply your post
            item = parseNotifyQuoteAndReply(el);
        } else if (el.hasClass("f_manage")) {
            //system info
            item = parseSystemInfo(el);
        } else if (el.hasClass("f_buddy")) {
            //system info
            item = parseFriendInfo(el);
        }

        if (item != null) {
            list.add(item);
        }
    }

    return list;
}
 
Example 12
Source File: Utils.java    From SteamGifts with MIT License 4 votes vote down vote up
/**
 * Load a single comment
 *
 * @param element           comment HTML element
 * @param commentId         the id of  the comment to be loaded
 * @param depth             the depth at which to display said comment
 * @param includeTradeScore whether or not to include +/- elements of the trading score, only visible in the trades section
 * @return the new comment
 */
@NonNull
public static Comment loadComment(Element element, long commentId, int depth, boolean includeTradeScore, Comment.Type type) {
    // TODO Since we're not passing any session information to Steam Trades, we can't edit. This is NOT feature complete for both trading & normal use

    // Save the content of the edit state for a bit & remove the edit state from being rendered.
    Element editState = type == Comment.Type.COMMENT ? element.select(".comment__edit-state.is-hidden textarea[name=description]").first() : null;
    String editableContent = null;
    if (editState != null)
        editableContent = editState.text();
    element.select(".comment__edit-state").html("");

    Element authorNode = element.select(type == Comment.Type.COMMENT ? ".comment__username" : ".author_name").first();
    String author = authorNode.text();
    boolean isOp = authorNode.hasClass("comment__username--op");

    String avatar = null;
    Element avatarNode = element.select(type == Comment.Type.COMMENT ? ".global__image-inner-wrap" : ".author_avatar").first();
    if (avatarNode != null)
        avatar = extractAvatar(avatarNode.attr("style"));

    Element timeCreated = element.select(type == Comment.Type.COMMENT ? ".comment__actions > div span" : ".action_list > span > span").first();

    String actions = type == Comment.Type.COMMENT ? ".comment__actions" : ".action_list";
    Uri permalinkUri = Uri.parse(element.select(actions + " a[href^=/go/]").first().attr("href"));

    Comment comment = includeTradeScore ? new TradeComment(commentId, author, depth, avatar, isOp, type) : new Comment(commentId, author, depth, avatar, isOp, type);
    comment.setPermalinkId(permalinkUri.getPathSegments().get(2));
    comment.setEditableContent(editableContent);
    comment.setCreatedTime(Integer.valueOf(timeCreated.attr("data-timestamp")));


    Element desc = element.select(type == Comment.Type.COMMENT ? ".comment__description" : ".review_description").first();
    desc.select("blockquote").tagName("custom_quote");
    String content = loadAttachedImages(comment, desc);
    comment.setContent(content);

    // check if the comment is deleted
    if (type == Comment.Type.COMMENT) {
        comment.setDeleted(element.select(".comment__summary").first().select(".comment__delete-state").size() == 1);
        comment.setHighlighted(element.select(".comment__parent > .comment__envelope").size() != 0);

        Element roleName = element.select(".comment__role-name").first();
        if (roleName != null)
            comment.setAuthorRole(roleName.text().replace("(", "").replace(")", ""));

        // Do we have either a delete or undelete link?
        comment.setDeletable(element.select(".comment__actions__button.js__comment-delete").size() + element.select(".comment__actions__button.js__comment-undelete").size() == 1);
    }

    if (comment instanceof TradeComment && !comment.isDeleted()) {
        try {
            ((TradeComment) comment).setTradeScorePositive(Utils.parseInt(element.select(".is_positive").first().text()));
            ((TradeComment) comment).setTradeScoreNegative(-Utils.parseInt(element.select(".is_negative").first().text()));
            ((TradeComment) comment).setSteamID64(Long.valueOf(Uri.parse(element.select(".author_name").attr("href")).getPathSegments().get(1)));
        } catch (Exception e) {
            Log.v(TAG, "Unable to parse feedback", e);
        }
    }

    return comment;
}
 
Example 13
Source File: Evaluator.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean matches(Element root, Element element) {
    return (element.hasClass(className));
}
 
Example 14
Source File: Evaluator.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean matches(Element root, Element element) {
    return (element.hasClass(className));
}
 
Example 15
Source File: Evaluator.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean matches(Element root, Element element) {
    return (element.hasClass(className));
}
 
Example 16
Source File: Evaluator.java    From jsoup-learning with MIT License 4 votes vote down vote up
@Override
public boolean matches(Element root, Element element) {
    return (element.hasClass(className));
}