I'm making a discord bot that checks the price of DogeCoin, and for that I decided to use BeautifulSoup to check the price (including the currency, which in this case is EUR) on this website: https://www.tradingview.com/symbols/DOGEEUR/?exchange=BINANCE . The price I want to get is immediately below DOGECOIN/EURO [binance symbol] BINANCE
However I'm new to BeautifulSoup and have very basic knowledge and experience with Python so this is quite a big challenge for me.
Is there a way to store the value of the coin + EUR to a string variable?
I tried using the following code as a reference, but even with tutorials I couldn't get any kind of results.
def get_crypto_price(coin):
#Get the URL
url = "https://www.google.com/search?q="+coin+"+price"
#Make a request to the website
HTML = requests.get(url)
#Parse the HTML
soup = BeautifulSoup(HTML.text, 'html.parser')
#Find the current price
#text = soup.find("div", attrs={'class':'BNeawe iBp4i AP7Wnd'}).text
text = soup.find("div", attrs={'class':'BNeawe iBp4i AP7Wnd'}).find("div", attrs={'class':'BNeawe iBp4i AP7Wnd'}).text
#Return the text
return text
#Create a main function to consistently show the price of the cryptocurrency
def main():
#Set the last price to negative one
last_price = -1
#Create an infinite loop to continuously show the price
while True:
#Choose the cryptocurrency that you want to get the price of (e.g. bitcoin, litecoin)
crypto = 'bitcoin'
#Get the price of the crypto currency
price = get_crypto_price()
#Check if the price changed
if price != last_price:
last_price = price #Update the last price
return price
time.sleep(3) #Suspend execution for 3 seconds.