Something like:
for anchor in tbody.findAll('div', style="s1"):
text = ''.join([x for x in anchor.contents if isinstance(x, bs4.element.NavigableString)])
works. Just know that you'll also get the line breaks in there, so .strip()
ing might be necessary.
For example:
for anchor in tbody.findAll('div', style="s1"):
text = ''.join([x for x in anchor.contents if isinstance(x, bs4.element.NavigableString)])
print([text])
print([text.strip()])
Prints
[u'
Here is text 3 and this is what I want.
']
[u'Here is text 3 and this is what I want.']
(I put them in lists so you could see the newlines.)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…