Issue
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 class="sc-15yy2pl-0 hzgCfk"><span class="icon-Caret-down"></span>3.69<!-- -->%</span></td>
<td style="text-align:right"><span class="sc-15yy2pl-0 hzgCfk"><span class="icon-Caret-down"></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.
Solution
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)
Answered By - Ahmed Khairy
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.