Reputation: 12910
I try to parse the fragments of html like this:
<div><span>adrress</span>text of address</div>
How can I take fragment 'text of address' programatically without span tag in Beatiful soup?
Now I take whole content of div and remove span, but I think there are a better way
Upvotes: 1
Views: 469
Reputation: 369424
>>> fragment = '<div><span>adrress</span>text of address</div>'
>>> soup = BeautifulSoup(fragment)
>>> soup.div.span.nextSibling
u'text of address'
Upvotes: 1
Reputation: 24802
here's how:
>>> from BeautifulSoup import BeautifulSoup
>>> text = "<div><span>address</span>text of address</div>"
>>> print BeautifulSoup(text).find('div').contents[-1]
text of address
Sorry for my first answer, I misread the question.
Upvotes: 0