In my scrapper I use .select("div.class-name") method but have a trouble: it returns non-separated values.
Structure of my html:
<div >
<div>Text1</div>
<div>Text2</div>
<div>Text3</div>
</div>
And as a result it gives me a list ["Text1Text2Text3"]. Is there any way to separate it as in html?
CodePudding user response:
You mean like this?
from bs4 import BeautifulSoup
sample_html = '''<div >
<div>Text1</div>
<div>Text2</div>
<div>Text3</div>
</div>'''
print(BeautifulSoup(sample_html, "lxml").select("div.class-name div"))
Output:
[<div>Text1</div>, <div>Text2</div>, <div>Text3</div>]