What's the best way to parse XML in Python?

8 Replies, 1685 Views

For parse XML Python, don’t overlook `BeautifulSoup`! It’s meant for HTML, but works great with XML too.

```python
from bs4 import BeautifulSoup
with open('file.xml') as f:
soup = BeautifulSoup(f, 'xml')
print(soup.find('tag').text)
```
It’s super forgiving with broken XML and has a simple API. Plus, the docs are beginner-friendly.

Messages In This Thread



Users browsing this thread: 1 Guest(s)