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


Java Elements.text方法代碼示例

本文整理匯總了Java中org.jsoup.select.Elements.text方法的典型用法代碼示例。如果您正苦於以下問題:Java Elements.text方法的具體用法?Java Elements.text怎麽用?Java Elements.text使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.jsoup.select.Elements的用法示例。


在下文中一共展示了Elements.text方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getSelectorByName

import org.jsoup.select.Elements; //導入方法依賴的package包/類
/**
 * 對與頁麵 的 一些動態通過js填充內容的select 的內容進行 提取,並封裝成Doc 元素
 * @param html
 * @return
 */
public static Element getSelectorByName(String html,String selectName){
	if(html==null) return null;
	Document doc = Jsoup.parse(html);
	Elements selectors =null;
	//先去頁麵拿 ,如果拿不到,或者拿到的是空的 列表,則在js拿
	selectors=doc.select("select[name="+selectName+"]");
	if(selectors!=null&&selectors.select("option").size()>0&&selectors.text()!=null&&!selectors.text().trim().equals("")){
		return selectors.first();
	} 
	//首先去js裏麵拿,拿不到再去頁麵拿
	selectors=doc.select("script");
	if(selectors!=null&&selectors.size()>0){
		String seletorHtml=selectors.html().replaceAll("[\\s\\S]*(<select[\\w\\W]*>[\\w\\W]+</select>)", "$1");
		Document docTemp = Jsoup.parse("<html>"+seletorHtml+"</html>");
		return docTemp.select("select[name="+selectName+"]").first();
	}
	
	return null;
}
 
開發者ID:liaojiacan,項目名稱:zhkuas_ssm_maven,代碼行數:25,代碼來源:HTMLUtil.java

示例2: getDetailNext

import org.jsoup.select.Elements; //導入方法依賴的package包/類
@Override
public String getDetailNext(String baseUrl, String currentUrl, byte[] result) throws UnsupportedEncodingException {
    Document document = Jsoup.parse(new String(result, "gb2312"));
    Elements elements = document.select("div.page a#nextpage");
    Elements elements1 = document.select("div.page a.current");
    if (elements.size() > 0 && elements1.size() > 0) {
        String current = elements1.text();
        Pattern pattern = Pattern.compile("http.*/");
        Matcher matcher = pattern.matcher(currentUrl);
        if (matcher.find()) {
            String href = elements.get(0).attr("href");
            Pattern pattern2 = Pattern.compile("[1-9]\\d*");
            Matcher matcher2 = pattern2.matcher(href);
            if (matcher2.find()) {
                String next = matcher2.group();
                if (current.equals(next))
                    return "";
                return matcher.group() + next + ".htm";
            }
        }
    }
    return "";
}
 
開發者ID:lanyuanxiaoyao,項目名稱:PicKing,代碼行數:24,代碼來源:Meizi4493.java

示例3: setData

import org.jsoup.select.Elements; //導入方法依賴的package包/類
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);
    }
}
 
開發者ID:7449,項目名稱:JsoupSample,代碼行數:15,代碼來源:JsoupPtFictionHomeManager.java

示例4: getAlbumTitle

import org.jsoup.select.Elements; //導入方法依賴的package包/類
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;
}
 
開發者ID:RipMeApp,項目名稱:ripme,代碼行數:72,代碼來源:ImgurRipper.java

示例5: run

import org.jsoup.select.Elements; //導入方法依賴的package包/類
@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);
}
 
開發者ID:mzlogin,項目名稱:guanggoo-android,代碼行數:62,代碼來源:GetTopicDetailTask.java

示例6: getDescription

import org.jsoup.select.Elements; //導入方法依賴的package包/類
public String getDescription(Document d) {
    Elements links = d.getElementsByTag("em");
    return links.text();
}
 
開發者ID:iomonad,項目名稱:hardwax,代碼行數:5,代碼來源:DescParser.java


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