BeautifulSoup4: change text inside xml tag
问题 I simply want to change the text inside an xml tag after it becomes a BeautifulSoup object. Current code: example_string = '<conversion><person>John</person></conversion>' bsoup = BeautifulSoup(example_string) bsoup.person.text = 'Michael' running this code in my console renders this error: Traceback (most recent call last): File "<stdin>", line 3, in <module> AttributeError: can't set attribute How can I change the value inside the person xml tag? 回答1: You need to set the .string attribute,