我正在尝试解析 CSS 文件以更改 html 的样式。查看示例 CSS 文本如下:p.FM_table_cell_body308 { margin-left:0.000pt; margin-right:0.000pt; text-align:left; text-indent:0.000pt;}p.FM_table_cell_body309 { margin-left:0.000pt; margin-right:0.000pt; text-align:left; text-indent:0.000pt;}p.FM_table_cell_body { margin-left:0.000pt; margin-right:0.000pt; text-align:left; text-indent:0.000pt;}我想改变'text-align:left;'的'left'这个词 在'p.FM_table_cell_body*** {'(*** 是数字)下的每个'中心'。所以,这就是我所期待的:p.FM_table_cell_body308 { margin-left:0.000pt; margin-right:0.000pt; text-align:center; text-indent:0.000pt;}p.FM_table_cell_body309 { margin-left:0.000pt; margin-right:0.000pt; text-align:center; text-indent:0.000pt;}p.FM_table_cell_body { # this has no number so should pass margin-left:0.000pt; margin-right:0.000pt; text-align:left; # no change text-indent:0.000pt;}这就是我正在编码的内容,如下所示:from bs4 import BeautifulSoupimport glob2 import rewith open ("C:\\TEST\\HTML\\Output_sample1\\Responsive HTML5\\Output.css","r",encoding="utf-8") as file_css : with open ("C:\\TEST\\HTML\\Output_sample1\\Responsive HTML5\\Output_test.css","wt",encoding="utf-8") as file_css_text_align : lines_css = file_css.readlines() for i_css, line_css in enumerate(lines_css[:-1]):但我试图制作的这段代码不起作用。此代码不是将 this(text-align:left;) 而是 (p.FM_table_cell_body*** {) 更改为 text-align:center; .你们会给我什么建议吗?
添加回答
举报
0/150
提交
取消