当前位置: 首页>>代码示例>>Java>>正文


Java Element.html方法代码示例

本文整理汇总了Java中org.jsoup.nodes.Element.html方法的典型用法代码示例。如果您正苦于以下问题:Java Element.html方法的具体用法?Java Element.html怎么用?Java Element.html使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jsoup.nodes.Element的用法示例。


在下文中一共展示了Element.html方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parseSelector

import org.jsoup.nodes.Element; //导入方法依赖的package包/类
private String parseSelector(Field f) {
    String selector = f.getAnnotation(Selector.class).value();

    Elements elems = doc.select(selector);

    if (elems.size() > 0) {
        final Element elem = elems.get(0);

        // Check which value annotation is present and retrieve data depending on the type of annotation
        if (f.isAnnotationPresent(TextValue.class)) {
            return elem.text();
        } else if (f.isAnnotationPresent(HtmlValue.class)) {
            return elem.html();
        } else if (f.isAnnotationPresent(AttributeValue.class)) {
            return elem.attr(f.getAnnotation(AttributeValue.class).name());
        } else
            return elem.text();
    }

    return null;
}
 
开发者ID:mintster,项目名称:nixmash-blog,代码行数:22,代码来源:JsoupHtmlParser.java

示例2: getContentNext

import org.jsoup.nodes.Element; //导入方法依赖的package包/类
@Override
public String getContentNext(String baseUrl, String currentUrl, byte[] result) throws UnsupportedEncodingException {
    Document document = Jsoup.parse(new String(result, "gbk"));
    Elements elements = document.select("script");
    for (Element element : elements) {
        String code = element.html();
        if (!element.html().equals("")) {
            Pattern pattern = Pattern.compile("index_\\d*.htm\">下一页");
            Matcher matcher = pattern.matcher(code);
            if (matcher.find()) {
                String temp = matcher.group();
                return baseUrl + "rosimm/" + temp.substring(0, temp.length() - 5);
            }
        }
    }
    return "";
}
 
开发者ID:lanyuanxiaoyao,项目名称:PicKing,代码行数:18,代码来源:RosiMM.java

示例3: main

import org.jsoup.nodes.Element; //导入方法依赖的package包/类
public static void main(String[] args) {
    
    String d = "<span><div>test</div></span>";
    Document doc = Jsoup.parse(d);
    Element div = doc.select("div").first(); // <div></div>
    div.html("<p>lorem ipsum</p>"); // <div><p>lorem ipsum</p></div>
    div.prepend("<p>First</p>");
    div.append("<p>Last</p>");
    // now: <div><p>First</p><p>lorem ipsum</p><p>Last</p></div>
    div.appendElement(d);
    Element span = doc.select("span").first(); // <span>One</span>
    span.wrap("<li><a href='http://example.com/'></a></li>");
    // now: <li><a href="http://example.com"><span>One</span></a></li>
    System.out.println(doc.html());
    
    String s = Jsoup.clean(doc.html(), "", Whitelist.relaxed(), new OutputSettings().prettyPrint(false));
    
    System.out.println(s);
}
 
开发者ID:bluetata,项目名称:crawler-jsoup-maven,代码行数:20,代码来源:JsoupTest.java

示例4: jsonToImage

import org.jsoup.nodes.Element; //导入方法依赖的package包/类
private String jsonToImage(Document page, String id) {
    Elements js = page.select("script[type=\"text/javascript\"]");
    for (Element tag : js) {
        if (tag.html().contains("window.__pageload")) {
            try {
                String script = tag.html();
                script = script.substring(script.indexOf("window.__pageload"));
                if (!script.contains(id)) {
                    continue;
                }
                script = script.substring(script.indexOf(id));
                // first },"src":"url" after id
                script = script.substring(script.indexOf("},\"src\":\"") + 9, script.indexOf("\",\"type\""));
                return script.replace("\\/", "/");
            } catch (StringIndexOutOfBoundsException e) {
                logger.debug("Unable to get json link from " + page.location());
            }
        }
    }
    return null;
}
 
开发者ID:RipMeApp,项目名称:ripme,代码行数:22,代码来源:DeviantartRipper.java

示例5: action

import org.jsoup.nodes.Element; //导入方法依赖的package包/类
public void action(JSONObject data) throws EventException {
	final JSONObject article = data.optJSONObject(Article.ARTICLE);

	String content = article.optString(Article.ARTICLE_CONTENT);

	final Document doc = Jsoup.parse(content, StringUtils.EMPTY, Parser.htmlParser());
	doc.outputSettings().prettyPrint(false);

	final StringBuilder listBuilder = new StringBuilder();

	listBuilder.append("<link rel=\"stylesheet\" type=\"text/css\" href=\"" + Latkes.getStaticServePath()
			+ "/plugins/list/style.css\" />");

	final Elements hs = doc.select("h1, h2, h3, h4, h5");

	listBuilder.append("<ul class='b3-solo-list'>");
	for (int i = 0; i < hs.size(); i++) {
		final Element element = hs.get(i);
		final String tagName = element.tagName().toLowerCase();
		final String text = element.text();
		final String id = "b3_solo_" + tagName + "_" + i;

		element.before("<span id='" + id + "'></span>");

		listBuilder.append("<li class='b3-solo-list-").append(tagName).append("'><a href='#").append(id)
				.append("'>").append(text).append("</a></li>");
	}
	listBuilder.append("</ul>");

	final Element body = doc.getElementsByTag("body").get(0);

	content = listBuilder.toString() + body.html();

	article.put(Article.ARTICLE_CONTENT, content);
}
 
开发者ID:daima,项目名称:solo-spring,代码行数:36,代码来源:ArticleController.java

示例6: doAnalysis

import org.jsoup.nodes.Element; //导入方法依赖的package包/类
public String doAnalysis(String html){
	if (html == null)
		return null;
	Document doc = null;
	doc = Jsoup.parse(html);
	Elements tables = doc.select("table");
	if (tables.size() < 1)
		return "获取不到选课结果";
	Element table = tables.get(0);
	Elements fonts = table.select("td").select("font");
	if (fonts.size() == 0)
		return "获取不到选课结果";
	String result = "";
	if (fonts.size() == 1)
		return fonts.get(0).html();
	for (Element font : fonts) {
		result += font.html() + "</br>";
	}
	return result;
}
 
开发者ID:liaojiacan,项目名称:zhkuas_ssm_maven,代码行数:21,代码来源:SubmitCourseResultAnalysiser.java

示例7: extractDataWithJsoup

import org.jsoup.nodes.Element; //导入方法依赖的package包/类
public void extractDataWithJsoup(String href){
	Document doc = null;
	try {
		doc = Jsoup.connect(href).timeout(10*1000).userAgent("Mozilla").ignoreHttpErrors(true).get();
	} catch (IOException e) {
		//Your exception handling here
	}
	if(doc != null){
		String title = doc.title();
		String text = doc.body().text();
		Elements links = doc.select("a[href]");
		for (Element link : links) {
			String linkHref = link.attr("href");
			String linkText = link.text();
			String linkOuterHtml = link.outerHtml(); 
			String linkInnerHtml = link.html();
		}
	}
}
 
开发者ID:PacktPublishing,项目名称:Java-Data-Science-Cookbook,代码行数:20,代码来源:JsoupTesting.java

示例8: getBannerUrl

import org.jsoup.nodes.Element; //导入方法依赖的package包/类
@Override
public String getBannerUrl() throws ParsingException {
    try {
        Element el = doc.select("div[id=\"gh-banner\"] style").first();
        String cssContent = el.html();
        String url = "https:" + Parser.matchGroup1("url\\((.*)\\)", cssContent);
        if (url.contains("s.ytimg.com")) {
            return null;
        } else {
            return url.substring(0, url.indexOf(");"));
        }


    } catch (Exception e) {
        throw new ParsingException("Could not get playlist Banner");
    }
}
 
开发者ID:TeamNewPipe,项目名称:NewPipeExtractor,代码行数:18,代码来源:YoutubePlaylistExtractor.java

示例9: parseElement

import org.jsoup.nodes.Element; //导入方法依赖的package包/类
/**
 * 抽取元素数据
 *
 * @param fieldElement
 * @param selectType
 * @param selectVal
 * @return
 */
public static String parseElement(Element fieldElement, XxlCrawlerConf.SelectType selectType, String selectVal) {
    String fieldElementOrigin = null;
    if (XxlCrawlerConf.SelectType.HTML == selectType) {
        fieldElementOrigin = fieldElement.html();
    } else if (XxlCrawlerConf.SelectType.VAL == selectType) {
        fieldElementOrigin = fieldElement.val();
    } else if (XxlCrawlerConf.SelectType.TEXT == selectType) {
        fieldElementOrigin = fieldElement.text();
    } else if (XxlCrawlerConf.SelectType.ATTR == selectType) {
        fieldElementOrigin = fieldElement.attr(selectVal);
    }  else if (XxlCrawlerConf.SelectType.HAS_CLASS == selectType) {
        fieldElementOrigin = String.valueOf(fieldElement.hasClass(selectVal));
    }  else {
        fieldElementOrigin = fieldElement.toString();
    }
    return fieldElementOrigin;
}
 
开发者ID:xuxueli,项目名称:xxl-crawler,代码行数:26,代码来源:JsoupUtil.java

示例10: extractContent

import org.jsoup.nodes.Element; //导入方法依赖的package包/类
private String extractContent(String id) {
    String result = getString(R.string.load_fail);
    try {
        Document doc = Jsoup.connect(PREFIX + id).get();
        Element content = doc.getElementsByClass("review-content").first();
        result = content.html();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return result;
}
 
开发者ID:Mindjet,项目名称:LiteReader,代码行数:12,代码来源:IncludeDoubanMovieReviewViewModel.java

示例11: getBannerUrl

import org.jsoup.nodes.Element; //导入方法依赖的package包/类
@Override
public String getBannerUrl() throws ParsingException {
    try {
        Element el = doc.select("div[id=\"gh-banner\"]").first().select("style").first();
        String cssContent = el.html();
        String url = "https:" + Parser.matchGroup1("url\\(([^)]+)\\)", cssContent);

        return url.contains("s.ytimg.com") || url.contains("default_banner") ? null : url;
    } catch (Exception e) {
        throw new ParsingException("Could not get Banner", e);
    }
}
 
开发者ID:TeamNewPipe,项目名称:NewPipeExtractor,代码行数:13,代码来源:YoutubeChannelExtractor.java

示例12: getValue

import org.jsoup.nodes.Element; //导入方法依赖的package包/类
private String getValue(Element element) {
    if (attrName == null) {
        return element.outerHtml();
    } else if ("innerHtml".equalsIgnoreCase(attrName)) {
        return element.html();
    } else if ("text".equalsIgnoreCase(attrName)) {
        return getText(element);
    } else if ("allText".equalsIgnoreCase(attrName)) {
        return element.text();
    } else {
        return element.attr(attrName);
    }
}
 
开发者ID:fengzhizi715,项目名称:NetDiscovery,代码行数:14,代码来源:CssSelector.java

示例13: getValue

import org.jsoup.nodes.Element; //导入方法依赖的package包/类
private <U> String getValue(Element node, Class<U> clazz) {
    if (node == null) {
        return defValue;
    }
    String value;
    switch (attribute) {
        case "":
            value = node.text();
            break;
        case "html":
        case "innerHtml":
            value = node.html();
            break;
        case "outerHtml":
            value = node.outerHtml();
            break;
        default:
            value = node.attr(attribute);
            break;
    }
    if (!clazz.equals(Date.class)
            && !clazz.equals(BigDecimal.class)
            && !format.equals(Selector.NO_VALUE)) {
        Pattern pattern = Pattern.compile(format);
        Matcher matcher = pattern.matcher(value);
        boolean found = matcher.find();
        if (found) {
            value = matcher.group(1);
            if (value.isEmpty()) {
                value = defValue;
            }
        }
    }
    return value;
}
 
开发者ID:DroidsOnRoids,项目名称:jspoon,代码行数:36,代码来源:HtmlField.java

示例14: getValue

import org.jsoup.nodes.Element; //导入方法依赖的package包/类
private String getValue(Element element, String attrName) {
	if (attrName == null) {
		return element.outerHtml();
	} else if ("innerHtml".equalsIgnoreCase(attrName)) {
		return element.html();
	} else if ("text".equalsIgnoreCase(attrName)) {
		return getText(element);
	} else if ("allText".equalsIgnoreCase(attrName)) {
		return element.text();
	} else {
		return element.attr(attrName);
	}
}
 
开发者ID:xbynet,项目名称:crawler,代码行数:14,代码来源:JsoupParser.java

示例15: onPostExecute

import org.jsoup.nodes.Element; //导入方法依赖的package包/类
@Override
protected void onPostExecute(Void aVoid) {
    TextView naam = (TextView) findViewById(R.id.textView5);
    TextView roll = (TextView) findViewById(R.id.textView);
    System.out.println(bookstatus);
    /*
    WebView wv = (WebView) view.findViewById(R.id.webView1);
    wv.getSettings().setSupportZoom(true);
    wv.getSettings().setSaveFormData(true);
    wv.getSettings().setBuiltInZoomControls(true);
    //wv.getSettings().setJavaScriptEnabled(true);
    wv.setWebViewClient(new WebViewClient());
    wv.setInitialScale(140);*/
    if(connected)
    {
        try{
            Element table = page.select("table[class=table table-bordered table-condensed table-striped]").first();
            tableHTML = table.html();
            tableHTML = "<table>" + tableHTML + "</table>";
            //  wv.loadDataWithBaseURL(null, tableHTML, "text/html", "utf-8", null);
            String nametable = page.select("div[class=container]").get(1).text();
            name = nametable.substring(nametable.indexOf(" ") + 1, nametable.indexOf("["));
            rno = nametable.substring(nametable.indexOf("["), nametable.indexOf("]") + 1);
            naam.setText((CharSequence)"Name:- " + name);
            roll.setText((CharSequence)"Roll Number:- " + rno);
        }
        catch(Exception e)
        {
            e.printStackTrace();
            Toast.makeText(getApplicationContext(),(CharSequence)"(2)AN internal error has made the app to force exit...Please try again ", Toast.LENGTH_SHORT).show();
        }
    }
    else
    {
        Toast.makeText(getApplicationContext(),(CharSequence)"(2)Network Communication Issues...Please try again later.", Toast.LENGTH_SHORT).show();
    }
}
 
开发者ID:anuragsai97,项目名称:Library-Token-Automation,代码行数:38,代码来源:Details.java


注:本文中的org.jsoup.nodes.Element.html方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。