1 回答
TA贡献1810条经验 获得超4个赞
您可能使用了错误的对象。尝试以下操作。
placemarks = kml_soup.find_all('Placemark')
for pm in placemarks:
LineString = pm.find('LineString')
if LineString:
print("LS found")
style = kml_soup.new_tag("Style")
style.string = "<LineStyle><width>3</width></LineStyle>"
LineString.insert_before(style) # Use LineString
这是另一个解决方案。
from simplified_scrapy import SimplifiedDoc,utils
html = utils.getFileContent('input.kml')
doc = SimplifiedDoc(html)
placemarks = doc.selects('Placemark')
for pm in placemarks:
LineString = pm.select('LineString')
if LineString:
print("LS found")
style = "<Style><LineStyle><width>3</width></LineStyle></Style>\n"+" "*6
LineString.insertBefore(style)
# print (doc.html)
添加回答
举报