当前位置: 首页>>代码示例>>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;未经允许,请勿转载。