Issue
Im trying to get the numbers from inside the div tag from the following html content <div class="nowPrice"><div class="showPrice" style="color: rgb(14, 203, 129);">47,864.58</div><div class="subPrice">$47,864.58</div></div>
What I need is
$47,864.5
Ive tried multiple ways of trying to extract this but i either keep getting errors or it returns an empty list as [] or none in the output This is my code
from bs4 import BeautifulSoup as soup
from urllib.request import urlopen as uReq
my_url = 'https://www.binance.com/en/trade/BTC_USDT?layout=basic'
uClient = uReq(my_url)
page_html = uClient.read()
uClient.close()
page_soup = soup(page_html, "html.parser")
ff = page_soup.find("div", class_= "subPrice").get_text()
print(ff)
This outputs None
EDIT: I tried using Selenium to get the data and it works
Solution
In edited question data load from javascript and you need library like selenium and you can't get data with BeautifulSoup.
This answer for old question:
If you have multiple class="subPrice", you can use find_all() and get price with .text like below:
from bs4 import BeautifulSoup
html="""
<div class="nowPrice">
<div class="showPrice" style="color: rgb(14, 203, 129);">47,864.58</div>
<div class="subPrice">$47,864.58</div>
<div class="subPrice">$57,864.58</div>
<div class="subPrice">$67,864.58</div>
<div class="subPrice">$77,864.58</div>
</div>
"""
soup=BeautifulSoup(html,"html.parser")
for sp in soup.find_all("div",class_="subPrice"):
print(sp.text)
output:
$47,864.58
$57,864.58
$67,864.58
$77,864.58
Answered By - user1740577
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.