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

The following are Jave code examples for showing how to use attr() 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: MyAnimeViewer   File: Parser.java   Source Code and License Vote up 6 votes
private String getVidStreamingVideo(String url) {
    String videoUrl = "";
    try {
        Document docdata = Jsoup.connect(url).userAgent(getUserAgent())
                .referrer("http://www.google.com")
                .timeout(Parser.getParseTimeOut()).get();
        Elements eles = docdata.select("div[class=videocontent]").select("video[id=my-video-player]").select("source");
        String tempUrl = "";
        if (eles != null && !eles.isEmpty()) {
            for (Element ele : eles) {
                tempUrl = ele.attr("abs:src");
                if (!TextUtils.isEmpty(tempUrl))
                    videoUrl = tempUrl;
            }
        } else {
            eles = docdata.select("div[class=videocontent]").select("iframe");
            if (eles != null && !eles.isEmpty()) {
                videoUrl = eles.attr("src");
                return getVideoFromProvider(videoUrl);
            }
        }
    } catch (IOException e) {
        WriteLog.appendLog(Log.getStackTraceString(e));
    }
    return videoUrl;
}
 
Example 2
Project: ripme   File: XhamsterRipper.java   Source Code and License Vote up 5 votes
@Override
public void rip() throws IOException {
    logger.info("Retrieving " + this.url);
    Document doc = Http.url(url).get();
    Elements videos = doc.select("div.player-container > a");
    if (videos.size() == 0) {
        throw new IOException("Could not find Embed code at " + url);
    }
    String vidUrl = videos.attr("href");
    addURLToDownload(new URL(vidUrl), HOST + "_" + getGID(this.url));
    waitForThreads();
}
 
Example 3
Project: CaptivePortalAutologin   File: HttpServer.java   Source Code and License Vote up 5 votes
private String absPath(String input, String baseUrl) {
    Document doc = Jsoup.parse(input);
    //doc.getAllElements();
    //doc.head().prepend("<base href=" + baseUrl +"> </base>");
    Elements link = doc.select("link");
    link.attr("href", baseUrl + "/" + link.attr("href"));

    return doc.toString();
}
 
Example 4
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 5
Project: corporate-game-share   File: WikiElementTranslator.java   Source Code and License Vote up 5 votes
public String extractLink(Element td) {
    Elements href = td.select("a");
    if (!href.isEmpty()) {
        //<i><a href="/wiki/1001_Spikes" title="1001 Spikes">1001 Spikes</a></i>
        return href.attr("href");
    }
    return null;
}
 
Example 6
Project: WebtoonDownloadManager   File: NaverEventController.java   Source Code and License Vote up 5 votes
/**
 * 웹툰별 에피소드 입력
 * 
 * @param webCode
 *            - 웹툰코드
 */
public void episodeSelect(String webCode) {
	try {

		Document document = Jsoup.connect("http://comic.naver.com/webtoon/list.nhn?titleId=" + webCode).get();
		Elements elements = document.select("ul.btn_group li").eq(1);
		String[] parseTag = elements.html().split("return");

		int index = parseTag[1].indexOf(")");
		String functionName = parseTag[1].substring(0, index);

		String firstEpisode = functionName.split(",")[1].replaceAll("'", "");
		sEp.setText(firstEpisode);

		elements = document.select("table.viewList > tbody > tr > td.title a").eq(0);
		String href = elements.attr("href");
		if ((!href.equals("")) || (href == null)) {
			String real_ep = href.split("no=")[1].split("&")[0];
			elements = document.select(".detail p");
			dEp.setText(real_ep);
		}

		sEp.setEditable(true);
		dEp.setEditable(true);

	} catch (Exception e) {
		e.printStackTrace();
	}

}
 
Example 7
Project: duck-feed-2   File: SiteScrape.java   Source Code and License Vote up 5 votes
public static String scrapeHtml(String webHtml) {
    Document doc = Jsoup.parse(webHtml);
    Elements rssTag = doc.select("link[type='application/atom+xml']");

    String rssHref = rssTag.attr("href");
    return rssHref;
}
 
Example 8
Project: ripme   File: ImgurRipper.java   Source Code and License Vote up 4 votes
public String getAlbumTitle(URL url) throws MalformedURLException {
    String gid = getGID(url);
    if (this.albumType == ALBUM_TYPE.ALBUM) {
        try {
            // Attempt to use album title as GID
            if (albumDoc == null) {
                albumDoc = Http.url(url).get();
            }

            Elements elems = null;

            /*
            // TODO: Add config option for including username in album title.
            // It's possible a lot of users would not be interested in that info.
            String user = null;
            elems = albumDoc.select(".post-account");
            if (elems.size() > 0) {
                Element postAccount = elems.get(0);
                if (postAccount != null) {
                    user = postAccount.text();
                }
            }
            */

            String title = null;
            final String defaultTitle1 = "Imgur: The most awesome images on the Internet";
            final String defaultTitle2 = "Imgur: The magic of the Internet";
            logger.info("Trying to get album title");
            elems = albumDoc.select("meta[property=og:title]");
            if (elems != null) {
                title = elems.attr("content");
                logger.debug("Title is " + title);
            }
            // This is here encase the album is unnamed, to prevent
            // Imgur: The most awesome images on the Internet from being added onto the album name
            if (title.contains(defaultTitle1) || title.contains(defaultTitle2)) {
                logger.debug("Album is untitled or imgur is returning the default title");
                // We set the title to "" here because if it's found in the next few attempts it will be changed
                // but if it's nto found there will be no reason to set it later
                title = "";
                logger.debug("Trying to use title tag to get title");
                elems = albumDoc.select("title");
                if (elems != null) {
                    if (elems.text().contains(defaultTitle1) || elems.text().contains(defaultTitle2)) {
                        logger.debug("Was unable to get album title or album was untitled");
                    }
                    else {
                        title = elems.text();
                    }
                }
            }

            String albumTitle = "imgur_";
            /*
            // TODO: Add config option (see above)
            if (user != null) {
                albumTitle += "user_" + user;
            }
            */
            albumTitle += gid;
            if (title != null) {
                albumTitle += "_" + title;
            }

            return albumTitle;
        } catch (IOException e) {
            // Fall back to default album naming convention
        }
    }
    return getHost() + "_" + gid;
}
 
Example 9
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 10
Project: MyAnimeViewer   File: GoGoAnime.java   Source Code and License Vote up 4 votes
@Override
public String getEpisodeVideo(String url) {
    String videoUrl = "";
    try {
        Document docdata = load(url, true);
        Elements videoEle = docdata.select("div[class=play-video]").select("iframe");
        if (videoEle != null && !videoEle.isEmpty()) {
            String tempUrl = videoEle.attr("abs:src");
            videoUrl = getVideoFromProvider(tempUrl);
            if (!TextUtils.isEmpty(videoUrl))
                return videoUrl;
        }
        Elements downloadEle = docdata.select("div[class=anime_video_body]")
                .select("div[class=download-anime]").select("a");
        if (downloadEle != null && !downloadEle.isEmpty()) {
            String downloadLink = downloadEle.get(0).attr("href");
            if (!TextUtils.isEmpty(downloadLink)) {
                videoUrl = getInternalVideoUrlAniUploader(downloadLink);
                if (!TextUtils.isEmpty(videoUrl)) {
                    return videoUrl;
                }
            }
        } else {
            Elements eles = docdata.select("div[id=video_container_div]").select("script");
            if (eles != null && !eles.isEmpty()) {
                Element playerScript = eles.last();
                if (playerScript != null) {
                    String scriptText[] = playerScript.html().split("\n");
                    if (scriptText != null && scriptText.length > 0) {
                        for (int i = 0; i < scriptText.length; i++) {
                            if (scriptText[i].contains("file:")) {
                                videoUrl = scriptText[i].trim().replace("file: '", "").replace("',", "");
                                break;
                            }
                        }
                    }
                }
                //videoUrl = eles.select("video").select("source").attr("abs:src");
            } else {
                eles = docdata.select("iframe[class=mirrorVid]");
                if (eles != null && !eles.isEmpty()) {
                    videoUrl = eles.attr("src");
                    if (!TextUtils.isEmpty(videoUrl))
                        videoUrl = getVideoFromProvider(videoUrl);
                }
            }
        }
    } catch (IOException e) {
        WriteLog.appendLog(Log.getStackTraceString(e));
    }
    return videoUrl;
}
 
Example 11
Project: ConnectU   File: TutoriasRequest.java   Source Code and License Vote up 4 votes
public List<TutoriaData> parseTutorias(boolean isNew, String text, SubjectData subject) {
    List<TutoriaData> tutorias = new ArrayList<>();
    try {
        JSONObject jdata = new JSONObject(text);
        if (jdata.has("aaData")) {
            JSONArray jarray = jdata.getJSONArray("aaData");
            for (int i = 0; i < jarray.length(); i++) {
                TutoriaData tutoria = new TutoriaData();
                JSONArray jtutoria = jarray.getJSONArray(i);
                String name;
                String state;
                String html;
                String id;
                if (isNew) {
                    name = jtutoria.getString(0);
                    state = "";
                    html = jtutoria.getString(3);
                    id = jtutoria.getString(4);
                } else {
                    name = jtutoria.getString(0);
                    state = jtutoria.getString(3);
                    if (state.contains("pendiente")) {
                        state = context.getString(R.string.tutoria_without_answer);
                    }
                    html = jtutoria.getString(4);
                    id = jtutoria.getString(5);
                }
                Document doc = Jsoup.parse(html);
                Elements elements = doc.select("img");
                String user = elements.attr("title");
                String src = elements.attr("src");

                String sname = AppManager.after(subject.getName(), parseYear() + " ");
                sname = AppManager.before(sname, "(" + subject.getId());

                tutoria.setSubject(subject.getId());
                tutoria.setSubjectName(sname);
                tutoria.setTitle(name);
                tutoria.setId(id);
                tutoria.setLastModify(state);
                tutoria.setTeacherName(user);
                tutoria.setTeacherPicture(src);
                tutorias.add(tutoria);
            }
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return tutorias;
}