I've been trying to extract data from span using BeautifulSoup, but somehow it is throwing an error.
HTML
<td style="text-align:right"><span ><span ></span>3.69<!-- -->%</span></td>
<td style="text-align:right"><span ><span ></span>5.33<!-- -->%</span></td>
My code to extract span data
page_content= BeautifulSoup(http.html, 'html.parser')
content= page_content.td.contents
data= content.span.string
I Want to extract 3.69% & 5.33% from span tag.
CodePudding user response:
Using find_all method
You can use find_all() method to find the text content of html and use just your own link
import requests
from bs4 import BeautifulSoup
result = requests.get(yourUrl)
src = result.content
soup = BeautifulSoup(src, "html.parser")
tds = soup.find_all("td")
contents = []
for td in tds:
content = td.find("span", {"class":"sc-15yy2pl-0 hzgCfk"}).find("span", {"class":"icon-Caret-down"}).text
contents.append(result)