Выходит непонятная ошибка, после парсинга курса валют на Python
Делаю парсинг курса доллара. Уже доделал, но тут выходит вот такая ошибка
AttributeError: 'set' object has no attribute 'items'
Поискал в паутине, не нашел. Прошу вашей помощи!
Вот сам код, заранее спасибо!)
import requests
from bs4 import BeautifulSoup
import time
import smtplib
class Currency:
# Ссылки
DOLLAR_RUB = 'https://www.google.com/search?q=%D0%BA%D1%83%D1%80%D1%81+%D0%B4%D0%BE%D0%BB%D0%BB%D0%B0%D1%80%D0%B0&rlz=1C1DVJR_ruRU878RU879&oq=%D0%BA%D1%83%D1%80%D1%81+%D0%B4%D0%BE%D0%BB%D0%BB%D0%B0%D1%80%D0%B0&aqs=chrome..69i57j0l7.4895j1j7&sourceid=chrome&ie=UTF-8'
headers = {'User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36'}
current_converted_price = 0
difference = 3
def __init__(self):
# Установка курса валюты при создании объекта
self.current_converted_price = float(self.get_currency_price().replace(",", "."))
# Метод для получения курса валюты
def get_currency_price(self):
# Парсим всю страницу
full_page = requests.get(self.DOLLAR_RUB, headers=self.headers)
soup = BeautifulSoup(full_page.content, 'html.parser')
convert = soup.findAll("span", {"class": "DFlfde", "class": "SwHCTb", "data-precision": 2})
return convert[0].text
# Проверка изменения валюты
def check_currency(self):
currency = float(self.get_currency_price().replace(",", "."))
if currency >= self.current_converted_price + self.difference:
print("Курс сильно вырос, может пора что-то делать?")
self.send_mail()
elif currency <= self.current_converted_price - self.difference:
print("Курс сильно упал, может пора что-то делать?")
self.send_mail()
print("Сейчас курс: 1 доллар = " + str(currency))
time.sleep(3)
self.check_currency()
# Отправка почты через SMTP
def send_mail(self):
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.ehlo()
server.login('[email protected]', 'yffuxdgmgainuhsn')
subject = 'Курс валют'
body = 'Курс доллара изменился'
message = f'Subject: {subject}\n{body}'
server.sendmail(
'[email protected]',
'[email protected]',
message
)
server.quit()
currency = Currency()
currency.check_currency()