Issue
Let's say I have the following HTML snippet:
<p class="toSelect">
"some text here..."
<br>
"Other text here..."
</p>
any suggestions to how to get the first text between the <p>
tag and its <br>
child tag using Beautifulsoup in Python?
Solution
You can select element <p class="toSelect">
and then .find_next
with text=True
:
from bs4 import BeautifulSoup
html_doc = """
<p class="toSelect">
"some text here..."
<br>
"Other text here..."
</p>"""
soup = BeautifulSoup(html_doc, "html.parser")
text = soup.select_one(".toSelect").find_next(text=True)
print(text)
Prints:
"some text here..."
Answered By - Andrej Kesely
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.