我试图使用lxml.html但我明白了
TypeError:参数必须是字节或unicode,得到“NoneType”
或者
TypeError:set()只接受2个位置参数(给定1个)
如果我使用
script.set('defer')
根据http://lxml.de/lxmlhtml.html
.set(键,值=无): 设置HTML属性。如果没有给定值,或者值为None,它将创建一个布尔属性,例如
^{pr2}$或者
<div custom-attribute></div>.
我的代码是
import lxml.html
htmldoc = lxml.html.parse( file )
headElement = htmldoc.find("head")
listOfScripts = headElement.xpath("script")
if len(listOfScripts) > 0:
for script in listOfScripts:
script.set('defer', value=None)
您链接的文档是针对
lxml
的最新版本,您所说的关于.set()
的功能是在版本3.7中添加的,但是您的版本是<;3.7查看变更日志here:
相关问题 更多 >
编程相关推荐