Rafael Martins Rafael Martins - 1 month ago 13
HTML Question

HTML Scraping with BeautifulSoup

I'm trying to search

<span>Status:</span>,
<span><strong>Moored</strong></span>,
<strong>Moored</strong


And pull out
Moored
. I've tried a lot of things but haven't been able to get it. Most recently
find(attrs={'span':'Status:'})
but that just returns
[]
. There are a lot of things tagged with
<strong>
in the HTML, but this is the only
<strong>
after a
<span>Status:


Edit: the HTML snipped above is a result of running
a = soup.find_all(attrs={'class':'vertical-offset-10 group-ib'})
then iterating over each loop with
a = (row.findChildren())


In the HTML:

<div class="vertical-offset-10 group-ib">
<span>Status:</span>
<span><strong>Moored</strong></span>
</div>


To clarify, all I want is the string
Moored

Answer
res = soup.find_all('span', text="Status:")
res[0].parent.find('strong').text

soup.find_all searches for all <span> tags that contain the text "Result:", then takes the next_sibling (the next <span> tag) and gets that tag's text contents.