Actua Corp C...">

Python - Beautiful Soup how to get first tag value

I have this tag:

<span class="companyName">Actua Corp <acronym title="Central Index Key">CIK</acronym>#: <a href="/cgi-bin/browse-edgar?action=getcompany&amp;CIK=0001085621&amp;owner=include&amp;count=40">0001085621 (see all company filings)</a></span>

      

How to get the value after <span class="companyName">

.

In this case it is Actua Corp.

I am open to all methods.

+3


source to share


1 answer


If you just want Actua Corp

, you can usenext

r = '<span class="companyName">Actua Corp <acronym title="Central Index Key">CIK</acronym>#: <a href="/cgi-bin/browse-edgar?action=getcompany&amp;CIK=0001085621&amp;owner=include&amp;count=40">0001085621 (see all company filings)</a></span>'

from bs4 import BeautifulSoup    
soup = BeautifulSoup(r)

span = soup.find('span', {'class': 'companyName'})
print(span.next)
>>> Actua Corp

      



If you want all text in span

, you can usetext

print(span.text)
>>> Actua Corp CIK#: 0001085621 (see all company filings)

      

+5


source







All Articles