Working on a cryptocurrency widget that scrapes html for specific cryptocurrency prices in real time but ran across AttributeError: 'NoneType' object has no attribute 'find'.
This issue happened all of a sudden and am really confused as to why it didn't show up much sooner. I've run the code many times before this moment with absolutely no issues. So my two questions are...
Why did this happen all of a sudden?
and
How do I fix this?
from tkinter import *
import requests
from bs4 import BeautifulSoup
from tkinter.ttk import *
from time import strftime
def get_crypto_price(coin):
url = "https://www.google.com/search?q=" + coin + "+price" # Defining link to coin
HTML = requests.get(url) # Requesting link access
soup = BeautifulSoup(HTML.text, 'html.parser') # Parser
text = soup.find("div", attrs={'class': 'BNeawe iBp4i AP7Wnd'}).find("div",
attrs={
'class': 'BNeawe iBp4i AP7Wnd'}).text # HTML Scrubber
return coin + ': ' + text + ' | '
root = Tk()
root.title('Crypto Widget 2021')
root.geometry('1080x40')
lab = Label(root)
lab.pack()
def update():
lab['text'] = get_crypto_price("Bitcoin") + get_crypto_price("Ethereum") + get_crypto_price(
"Litecoin") + get_crypto_price("Dogecoin")
lab.after(5000, update)
update()
def time():
string = strftime('%H:%M %p')
lbl.config(text=string)
lbl.after(5000, time)
lbl = Label(root, font=('times new roman', 10, 'bold'),
background='white',
foreground='black')
lbl.pack(anchor='n')
time()
root.mainloop()