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&CIK=0001085621&owner=include&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.
source to share
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&CIK=0001085621&owner=include&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)
source to share