本文整理汇总了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);
}
示例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);
}
示例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;
}
示例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;
}
}
示例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;
}
示例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);
}
示例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());
}
}
示例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);
}
示例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());
}
示例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());
}
示例11: extractText
import org.jsoup.Jsoup; //导入方法依赖的package包/类
public static String extractText(String html) {
return Jsoup.clean(html, Whitelist.none());
}
示例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);
}
示例13: clean
import org.jsoup.Jsoup; //导入方法依赖的package包/类
public static String clean(String s, Whitelist list) {
return Jsoup.clean(s, list);
}
示例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));
}
示例15: getEscapedValue
import org.jsoup.Jsoup; //导入方法依赖的package包/类
public String getEscapedValue() {
return Jsoup.clean(getValue(), Whitelist.basic());
}