You can specify xml in bs4 when instantiating the BeautifulSoup object:
xml_soup = BeautifulSoup(xml_object, 'xml')
This should take care of your problem. You can use the xml_soup object to parse the remaining html, however I would recommend creating an instance of another soup object specifically for html:
soup = BeautifulSoup(html_object)
source share