Issue
In my scrapper I use .select("div.class-name") method but have a trouble: it returns non-separated values.
Structure of my html:
<div class="class-name">
<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?
Solution
You mean like this?
from bs4 import BeautifulSoup
sample_html = '''<div class="class-name">
<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>]
Answered By - baduker
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.