如何从Java中的html代码中删除/替换以下内联css样式

如何从Java中的html代码中删除/替换以下内联css样式,java,Java,我有一个html页面,其中包括以下主重置css。我将得到java中作为字符串的html代码,我必须使用java从中删除/替换/注释css代码后面的内容。在删除/替换下面的css时,我必须排除其他内联css样式。我尝试使用StringUtils类,但它不起作用。我如何在java中做到这一点 <style type="text/css"> @charset "utf-8"; /* CSS Document */ /* Ver 1.0 Author*/ /

我有一个html页面,其中包括以下主重置css。我将得到java中作为字符串的html代码,我必须使用java从中删除/替换/注释css代码后面的内容。在删除/替换下面的css时,我必须排除其他内联css样式。我尝试使用StringUtils类,但它不起作用。我如何在java中做到这一点

<style type="text/css"> 
    @charset "utf-8";
    /* CSS Document */
    /* Ver 1.0 Author*/
    /* master reset */
    a,abbr,acronym,address,applet,b,big,blockquote,body,button,caption,center,cite,code,dd,del,dfn,
    dir,div,dl,dt,em,embed,fieldset,font,form,frame,h1,h2,h3,h4,h5,h6,hr,html,i,iframe,img,input,
    ins,kbd,label,legend,li,menu,object,ol,option,p,pre,q,s,samp,select,small,span,strike,strong,
    sub,sup,table,tbody,td,textarea,tfoot,th,thead,tr,tt,u,ul,var
    {background:transparent;border:0;font-family:inherit;font-size:100%;font-style:inherit;
    font-weight:inherit;margin:0;outline:0;padding:0;vertical-align:baseline;}

    html {font-size:1em;overflow-y:scroll;}
    body {background:white;color:black;line-height:1;}

    a,ins {text-decoration:none;}
    blockquote,q{quotes:none;quotes:"" "";}
    blockquote:before,blockquote:after,q:before,q:after {content:"";content:none;}
    caption,center,td,th {text-align:left;}
    del {text-decoration:line-through;}
    dir,menu,ol,ul {list-style:none;}
    table {border-collapse:collapse;border-spacing:0;}
    textarea {overflow-y:auto;}
</style>

@字符集“utf-8”;
/*CSS文档*/
/*1.0版作者*/
/*主复位*/
a、 缩写、首字母缩写、地址、小程序、b、大、块引号、正文、按钮、标题、中心、引用、代码、dd、del、dfn、,
目录、div、dl、dt、em、嵌入、字段集、字体、表单、帧、h1、h2、h3、h4、h5、h6、hr、html、i、iframe、img、输入、,
ins、kbd、标签、图例、li、菜单、对象、ol、选项、p、pre、q、s、samp、select、small、span、strike、strong、,
sub、sup、表格、tbody、td、textarea、tfoot、th、THAD、tr、tt、u、ul、var
{背景:透明;边框:0;字体系列:继承;字体大小:100%;字体样式:继承;
字重:继承;边距:0;轮廓:0;填充:0;垂直对齐:基线;}
html{字体大小:1em;溢出-y:scroll;}
正文{背景:白色;颜色:黑色;线条高度:1;}
a、 ins{文本装饰:无;}
blockquote,q{quotes:none;quotes:“”;}
blockquote:before,blockquote:after,q:before,q:after{content:;content:none;}
标题,中间,td,th{文本对齐:左;}
del{text装饰:线穿过;}
目录,菜单,ol,ul{列表样式:无;}
表{边框折叠:折叠;边框间距:0;}
textarea{overflow-y:auto;}

我建议使用一个HTML解析库,比如

使用JSoup,您可以使用标记名选择某些元素(基于它们的标记名、id等)。例如,要删除所有
样式
元素:

Document doc = Jsoup.parse(html);
Elements els = doc.select("style");
for(Element e: els){
    e.remove();
}