Issue
I was scraping a site using Beautifulsoup, and found text between 2 span elements (not between opening and closing tags).
How can I scrap the text between two span elements, such as:
<span class="description_start"></span>
Text which I need to scrape
<span class="description_end"></span>
Solution
Try to find first <span>
and then .find_next(text=True)
:
from bs4 import BeautifulSoup
html_doc = """\
<span class="description_start"></span>
Text which I need to scrape
<span class="description_end"></span>"""
soup = BeautifulSoup(html_doc, "html.parser")
t = soup.find("span", class_="description_start").find_next(text=True)
print(t)
Prints:
Text which I need to scrape
Answered By - Andrej Kesely
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.