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


Java Jsoup.clean方法代碼示例

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


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

示例1: main

import org.jsoup.Jsoup; //導入方法依賴的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

示例2: main

import org.jsoup.Jsoup; //導入方法依賴的package包/類
public static void main(String[] args) {
	String baseUri = "http://www.baidu.com";
	String html = "<a href=\"http://www.baidu.com/gaoji/preferences.html\"name=\"tj_setting\">搜索設置</a>";
	String doc = Jsoup.clean(html, baseUri, Whitelist.none());
	System.out.println(doc);
	System.out.println("*******");
	doc = Jsoup.clean(html, baseUri, Whitelist.simpleText());
	System.out.println(doc);
	System.out.println("*******");
	doc = Jsoup.clean(html, baseUri, Whitelist.basic());
	System.out.println(doc);
	System.out.println("*******");
	doc = Jsoup.clean(html, baseUri, Whitelist.basicWithImages());
	System.out.println(doc);
	System.out.println("*******");
	doc = Jsoup.clean(html, baseUri, Whitelist.relaxed());
	System.out.println(doc);

}
 
開發者ID:vindell,項目名稱:docx4j-template,代碼行數:20,代碼來源:XHTMLDocumentHandler.java

示例3: createReply

import org.jsoup.Jsoup; //導入方法依賴的package包/類
public Reply createReply(ReplyDTO replyDTO, User user) {
    replyDTO.setUserId(user.getId());
    Reply reply = replyDTO.toReply();

    String content = Jsoup.clean(reply.getContent(), Whitelist.basicWithImages());
    content = updateAtUser(content);

    reply.setContent(content);
    reply.setStatus(ReplyStatus.ACTIVE);

    Reply result = replyRepository.save(reply);

    reply.setUser(user);

    afterCreatingReply(reply);
    return result;
}
 
開發者ID:ugouku,項目名稱:shoucang,代碼行數:18,代碼來源:ReplyService.java

示例4: getDescription

import org.jsoup.Jsoup; //導入方法依賴的package包/類
public String getDescription(String page) {
    try {
        // Fetch the image page
        Response resp = Http.url(page)
                .referrer(this.url)
                .response();
        cookies.putAll(resp.cookies());

        // Try to find the description
        Elements els = resp.parse().select("td[class=alt1][width=\"70%\"]");
        if (els.size() == 0) {
            logger.debug("No description at " + page);
            throw new IOException("No description found");
        }
        logger.debug("Description found!");
        Document documentz = resp.parse();
        Element ele = documentz.select("td[class=alt1][width=\"70%\"]").get(0); // This is where the description is.
        // Would break completely if FurAffinity changed site layout.
        documentz.outputSettings(new Document.OutputSettings().prettyPrint(false));
        ele.select("br").append("\\n");
        ele.select("p").prepend("\\n\\n");
        logger.debug("Returning description at " + page);
        String tempPage = Jsoup.clean(ele.html().replaceAll("\\\\n", System.getProperty("line.separator")), "", Whitelist.none(), new Document.OutputSettings().prettyPrint(false));
        return documentz.select("meta[property=og:title]").attr("content") + "\n" + tempPage; // Overridden saveText takes first line and makes it the file name.
    } catch (IOException ioe) {
        logger.info("Failed to get description " + page + " : '" + ioe.getMessage() + "'");
        return null;
    }
}
 
開發者ID:RipMeApp,項目名稱:ripme,代碼行數:30,代碼來源:FuraffinityRipper.java

示例5: stripHtmlFrom

import org.jsoup.Jsoup; //導入方法依賴的package包/類
public String stripHtmlFrom(String original)

	{
		// If there's no content, return to sender unopened
		if( Check.isEmpty(original) )
		{
			return original;
		}

		String cleaned = Jsoup.clean(original, Whitelist.simpleText());

		return cleaned;
	}
 
開發者ID:equella,項目名稱:Equella,代碼行數:14,代碼來源:FlickrSearchResultsSection.java

示例6: createPost

import org.jsoup.Jsoup; //導入方法依賴的package包/類
@Transactional
@Timed
@Caching(evict = {
    @CacheEvict(value = TagService.CACHE_COUNT_USER, key = "#postDTO.userId.toString().concat('_posts_count')"),
    @CacheEvict(value = CACHE_COUNT_USER_TAG_POSTS, key = "#postDTO.userId.toString().concat('_tags_posts_count')", allEntries = true),
})
public Optional<Post> createPost(PostDTO postDTO) throws JSONException {
    Post post = postMapper.postDTOToPost(postDTO);
    String result = getWebPost(String.format(SERVER_URL, post.getUrl()));

    if (result == null)
        return Optional.empty();

    JSONObject json = new JSONObject(result);
    String content = json.getString("content");

    // Filter html tags
    content = Jsoup.clean(content, Whitelist.relaxed());

    post.setTitle(json.getString("title"));
    post.setTitle(post.getTitle().substring(0, Math.min(255, post.getTitle().length())));
    post.setContent(content);
    post.setDomain(json.getString("host"));

    updateTags(post, null);
    saveNewPost(post);

    return Optional.of(post);
}
 
開發者ID:ugouku,項目名稱:shoucang,代碼行數:30,代碼來源:PostService.java

示例7: getArticle

import org.jsoup.Jsoup; //導入方法依賴的package包/類
/**
 * Get full text of a post
 */
public void getArticle(Post post) {
    log.debug("Handle crawling article full text from source site, id=" + post.getId() + " , url=" + post.getUrl());

    try {
        String result = postService.getWebPost(String.format(PostService.SERVER_URL, post.getUrl()));
        if (result == null) {
            log.error("Failed to get article full text, id=" + post.getId());
            return;
        }

        Post resultPost = postRepository.findOne(post.getId());
        if (resultPost == null) {
            log.warn("Cancel crawling article full text of post id=" + post.getId() + ", because the post does not exist.");
            return;
        }

        JSONObject json = new JSONObject(result);
        String content = json.getString("content");
        content = Jsoup.clean(content, Whitelist.relaxed());
        resultPost.setContent(content);

        postService.saveNewPost(resultPost);
    } catch (Exception e) {
        log.error("Failed to resolve article full text, id=" + post.getId() + ", url=" + post.getUrl() + ", exception: " + e.getMessage());
    }
}
 
開發者ID:ugouku,項目名稱:shoucang,代碼行數:30,代碼來源:RabbitConsumer.java

示例8: forClass

import org.jsoup.Jsoup; //導入方法依賴的package包/類
public static SimClassInfo forClass(Class<?> cls) {

        Optional<ClassJavadoc> javadoc = RuntimeJavadoc.getJavadoc(cls);
        String comment = javadoc.map(ClassJavadoc::getComment).map(Comment::toString).orElse("");
        String sanitizedComment = Jsoup.clean(comment, Whitelist.basic());
        return new SimClassInfo(cls.getCanonicalName(), sanitizedComment);
    }
 
開發者ID:etomica,項目名稱:etomica,代碼行數:8,代碼來源:SimClassInfo.java

示例9: formatHtml

import org.jsoup.Jsoup; //導入方法依賴的package包/類
@Override
protected String formatHtml(String content) {
    Element body = Jsoup.parse(content).body();
    Element contentDiv = body.select("div[dir='ltr']").first();
    if (contentDiv == null) {
        log.warn("Found no valid content in e-mail from Gmail, returning empty");
        return "";
    }

    while (contentDiv.children().size() > 0 && contentDiv.children().last().is("br")) {
        contentDiv.children().last().remove();
    }

    return Jsoup.clean(contentDiv.html(), Whitelist.basic());
}
 
開發者ID:kamax-io,項目名稱:matrix-appservice-email,代碼行數:16,代碼來源:GmailClientFormatter.java

示例10: formatHtml

import org.jsoup.Jsoup; //導入方法依賴的package包/類
@Override
protected String formatHtml(String content) {
    Element body = Jsoup.parse(content).body();
    body.select("blockquote[cite]").remove();
    body.select("div.moz-cite-prefix").remove();

    while (body.children().size() > 0 && body.children().last().is("br")) {
        body.children().last().remove();
    }

    return Jsoup.clean(body.html(), Whitelist.basic());
}
 
開發者ID:kamax-io,項目名稱:matrix-appservice-email,代碼行數:13,代碼來源:ThunderbirdClientFormatter.java

示例11: extractText

import org.jsoup.Jsoup; //導入方法依賴的package包/類
public static String extractText(String html) {
    return Jsoup.clean(html, Whitelist.none());
}
 
開發者ID:philipwhiuk,項目名稱:q-mail,代碼行數:4,代碼來源:HtmlHelper.java

示例12: htmlFilter

import org.jsoup.Jsoup; //導入方法依賴的package包/類
private static String htmlFilter(String html,String baseUri) {
	if(StringUtil.isBlank(html)) return "";
	return Jsoup.clean(html, baseUri,myWhiteList);
}
 
開發者ID:wrayzheng,項目名稱:webpage-update-subscribe,代碼行數:5,代碼來源:PageParser.java

示例13: clean

import org.jsoup.Jsoup; //導入方法依賴的package包/類
public static String clean(String s, Whitelist list) {
	return Jsoup.clean(s, list);
}
 
開發者ID:rafjordao,項目名稱:Nird2,代碼行數:4,代碼來源:HtmlUtils.java

示例14: getServerConsole

import org.jsoup.Jsoup; //導入方法依賴的package包/類
@Retryable(backoff = @Backoff(2000L))
public String getServerConsole(String subId) throws IOException {
    String bodyHtml = validate(getPanelView(subId, "console_log")).body().toString();
    return Jsoup.clean(bodyHtml, "", Whitelist.none(), new Document.OutputSettings().prettyPrint(false));
}
 
開發者ID:quanticc,項目名稱:sentry,代碼行數:6,代碼來源:GameAdminService.java

示例15: getEscapedValue

import org.jsoup.Jsoup; //導入方法依賴的package包/類
public String getEscapedValue() {
	return Jsoup.clean(getValue(), Whitelist.basic());
}
 
開發者ID:kalsowerus,項目名稱:Guestbook9001,代碼行數:4,代碼來源:EscapeTag.java


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