-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscratch_19.py
More file actions
29 lines (21 loc) · 918 Bytes
/
Copy pathscratch_19.py
File metadata and controls
29 lines (21 loc) · 918 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import re
# 正则表达式匹配需要删除的CSS规则
pattern = re.compile(r'\.art_size-(?:low|med|high)\b.*?\{[^}]*\}', re.DOTALL)
def remove_css_rules(css_file_path):
try:
# 读取CSS文件
with open(css_file_path, 'r', encoding='utf-8') as file:
css_content = file.read()
# 删除匹配的CSS规则
new_css_content = re.sub(pattern, '', css_content)
# 写回修改后的CSS内容到新文件
with open(css_file_path, 'w', encoding='utf-8') as file:
file.write(new_css_content)
print("CSS规则已删除。")
except FileNotFoundError:
print("文件未找到,请检查文件路径。")
except Exception as e:
print(f"发生错误:{e}")
# 调用函数,传入CSS文件的路径
css_file_path = r'.\output_cards\cardart-v9.css' # 替换为你的CSS文件路径
remove_css_rules(css_file_path)