Aug-28-2020, 04:09 PM
Hello,
Using BeautifulSoup, I can't figure out how to add a new element to the current block:
Using BeautifulSoup, I can't figure out how to add a new element to the current block:
from bs4 import BeautifulSoup as Soup with open('track.kml') as data: kml_soup = Soup(data, 'lxml-xml') # Parse as XML placemarks = kml_soup.find_all('Placemark') for pm in placemarks: if pm.find('LineString'): print("LS found") #How to insert new element before LineString? #TypeError: 'NoneType' object is not callable tag = pm.new_tag("Blah") tag.string = "<Another>blah</Another>" pm.string.insert_after(tag) print(pm)Thank you.