Reputation: 9
I am working on this project where the information I need is included in the button on the website. I am trying to scrape the number where the 97,800 is right now using python. This number changes every time the page refreshes. I have not tried anything yet because I am new to HTML with python. How would I go about this? Thank You.
Forgot to mention this but the number changes every second and I need to find a way where it pulls html from the url and not hardcoding the html ahead of time.
<div class="form-block">
<button name="button" type="submit" data-disable-with="Please wait..." data-
confirm="Are you sure?" class="title-button">
"Sell Now at "
<img class="icons-stubs" src="randomphotourl.com">
" 97,800 "
</button>
</div>
Upvotes: 0
Views: 1099
Reputation: 99
Try this:
import requests
from bs4 import BeautifulSoup
#input your url
url=" "
r1=requests.get(url)
c1=r1.content
soup1=BeautifulSoup(c1,"html.parser")
# Finding the location of button....Using find_all gives a list. You can
# reference the exact button by filling the "NuM" below with the index
# of the particular element
btn = soup1.find_all("button", {"class": "title-button"})[NuM].text
btn_text = btn.replace("Sell Now at ","")
Upvotes: 0
Reputation: 195563
One possible solution is to select the <button>
tag and use the .contents
property:
from bs4 import BeautifulSoup
html_doc = """
<div class="form-block">
<button name="button" type="submit" data-disable-with="Please wait..." data-
confirm="Are you sure?" class="title-button">
"Sell Now at "
<img class="icons-stubs" src="randomphotourl.com">
" 97,800 "
</button>
</div>
"""
soup = BeautifulSoup(html_doc, "html.parser")
value = soup.select_one("button").contents[-1].strip(' "\n')
print(value)
Prints:
97,800
Upvotes: 2