【发布时间】:2020-10-10 03:09:38
【问题描述】:
这是目标
<?xml version="1.0"?>
<opencv_storage>
<intr type_id="opencv-matrix">
<rows>3</rows>
<cols>3</cols>
<dt>d</dt>
<data>
1.4575724387217269e+03 0. 1.2129456942116219e+03 0.
1.4575222265029629e+03 1.0073205884892100e+03 0. 0. 1.</data></intr>
</opencv_storage>
这是我的尝试
from bs4 import BeautifulSoup
soup = BeautifulSoup(features = "xml")
parent = soup.new_tag("opencv_storage")
soup.append(parent)
t = soup.parent
child_row = soup.new_tag("rows")
child_row.string = str(3)
soup.parent.insert_child(child_row)
哪个会产生错误
Traceback (most recent call last):
File "/home/test.py", line 22, in <module>
soup.parent.insert_child(child_row)
AttributeError: 'NoneType' object has no attribute 'insert_child'
除了告诉我如何纠正这个错误,请提供命令参考
【问题讨论】:
标签: beautifulsoup tags parent-child