为了使这个问题更容易理解,下面是一个例子
<Tag name="Thumbnail" inline="no" nonsearchable="yes">
<Attribute>
<Attribute name="AText" Searchable="yes"></Attribute>
</Attribute>
</Tag>
<Tag name="Label" inline="no" nonsearchable="yes">
<Attribute>
<Attribute name="AText" Searchable="no"></Attribute>
</Attribute>
</Tag>
<Tag name="Image" inline="no" nonsearchable="yes">
<Attribute>
<Attribute name="BText" Searchable="yes">
</Attribute>
</Tag>
<Tag name="Wonder" inline="no" nonsearchable="yes">
<Attribute>
<Attribute name="BText" Searchable="yes"></Attribute>
</Attribute>
</Tag>
预期结果
所以在excel中,第一行应该是属性标记的名称值,如果属性的标记的可搜索的值为“是”,那么这些“限定的”属性标记的父标记-标记—名称值。在
目前,我只能找到所有标记的名称值,如果其子项的可搜索值为“是”,但无法将它们归类到相应的属性标记的名称值下。以下是我的初始代码:
^{pr2}$我也会设法解决这个问题,但为了使过程更快,如果你有任何想法,请提出建议。谢谢您!!在
您的代码找不到任何内容,如果您打印
AttrYES
,它将是[]
。问题是,当您将bs4
与解析器lxml
一起使用时,所有标记和属性名都将转换为小写,请参考official doc。如果你打印汤,它会给你:因此,您可以这样修改代码:
^{pr2}$打印内容为:
^{3}$然后您可以将它们写入excel文件:
result.xlsx
将是:更新:使用openpyxl
相关问题 更多 >
编程相关推荐