如何删除整个文档中特定元素的所有属性。我正在尝试这样的事情:
from bs4 import UnicodeDammit
from lxml import html
content = open("source.html").read()
document = UnicodeDammit(content, is_html=True)
parser = html.HTMLParser(encoding=document.original_encoding)
root = html.document_fromstring(content, parser=parser)
for attr in root.xpath('.//table/@*'):
del attr.attrib
Run Code Online (Sandbox Code Playgroud)
在这里,我尝试使用 xpath 从文档中的所有表中删除所有属性,但它不起作用。
我们有一个在 YAML 中存储设置的项目(设置文件由 ansible 脚本生成)。现在我们使用 pyyaml 来解析 YAML 格式,并使用 marshmallow 来验证设置。我对在 YAML 中存储设置感到非常满意,但我不认为 marshmellow 是我需要的工具(模式很难阅读,我不需要设置序列化,想要 xsd 之类的东西)。那么验证项目中设置的最佳实践是什么,也许有独立于语言的方式?(我们使用的是python 2.7)
YAML 设置:
successive:
worker:
cds_process_number: 0 # positive integer or zero
spider_interval: 10 # positive integer
run_worker_sh: /home/lmakeev/CDS/releases/master/scripts/run_worker.sh # OS path
allow:
- "*" # regular expression
deny:
- "^[A-Z]{3}_.+$" # regular expression
Run Code Online (Sandbox Code Playgroud)