公司是前后端分离的架构,有个功能前端使用了富文本编辑器,通过该富文本编辑器得到的html文本与实际要求有一定差距,但是前端又处理不了,因此该处理只能由我们后端处理了。
第一想法是通过处理XML文档的方式处理前端传来html文本,由于前端传来的html文本并不是规范的XML,因此只能考虑其他方法。
后来发现Jsoup可以解析html文本,解决了问题。

class Test {
    public static void main(String[] args) {
        // 获取html文档。
        Document document = Jsoup.parse("<img><img>");
        // 拿到全部img标签,并设置src属性
        Iterator<Element> imgs = document.select("img").iterator();
        while (imgs.hasNext()) {
            Element img = imgs.next();
            img.attr("src", "http://xxx.com");
        System.out.println(document);
 <head></head>
  <img src="http://xxx.com" />
  <img src="http://xxx.com" />
 </body>
</html>
                      公司是前后端分离的架构,有个功能前端使用了富文本编辑器,通过该富文本编辑器得到的html文本与实际要求有一定差距,但是前端又处理不了,因此该处理只能由我们后端处理了。   第一想法是通过处理XML文档的方式处理前端传来html文本,由于前端传来的html文本并不是规范的XML,因此只能考虑其他方法。   后来发现Jsoup可以解析html文本,解决了问题。class Test {  ...
1.document.title    //设置文档的标题(HTML的title标签)
2.document.bgColor   //设置背景页面的颜色
3.document.fgColor    //设置前景色(文本颜色)
4.documen.URL        //设置URL属性在同一个窗口打开其他页面
5.document.linkColor  //未点击过的链接颜色
6....
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.io.IOException;
public class HTMLParser {
    public static void main(String[] args) throws IOException {
        // 使用 Jsoup 解析 HTML
        Document doc = Jsoup.connect("https://www.example.com").get();
        // 选择所有的标题元素
        Elements titles = doc.select("h1");
        for (Element title : titles) {
            System.out.println("标题:" + title.text());
在这段代码中,我们使用了 Jsoup 库解析 HTML,然后选择了所有的标题元素(标签为 `h1`)并输出其文本内容。
				Swagger异常:AbstractSerializableParameter   : Illegal DefaultValue null for parameter type integer解决方案
					29800
                Swagger异常:AbstractSerializableParameter   : Illegal DefaultValue null for parameter type integer解决方案
                    wangbaominflipped: 
                    成功了!!!
                layui 树形组件(tree)支持双击事件
                    weixin_41775080: 
                    单击和双击同时存在就不能生效
                Docker安装、破解、配置JIRA-7.13
                    技术红海: 
                    运行起来之后,数据库是空库,怎么登陆jira呢
                lombok @Accessors用法
                    误逐世间乐: 
                    同意,排版工整,言简意赅
                Swagger异常:AbstractSerializableParameter   : Illegal DefaultValue null for parameter type integer解决方案
                    墨客小书虫: 
                    成功解决,牛逼大佬