D
D
dyrtage62020-06-16 15:01:25
Python
dyrtage6, 2020-06-16 15:01:25

There is an incorrect value in the parser of the VK bot exchange rate, what should I do?

I am making a currency exchange parser. I take the course info from the Google page. The bot answers, but writes that the dollar is 0.89, how to make it show correctly.
Removed other functions in the code -

from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType
import vk_api
import random
import wikipedia
import time
import requests
from bs4 import BeautifulSoup

vk = vk_api.VkApi(token="какой то токен")
vk._auth_token()
vk.get_api()
longpoll = VkBotLongPoll(vk, какой то айди)

play = ["Бумага", "Ножницы", "Камень"]
wikipedia.set_lang("RU")

while True:
    try:
        for event in longpoll.listen():
            if event.type == VkBotEventType.MESSAGE_NEW:
                if event.object.peer_id != event.object.from_id:
                    if "/курс" in event.object.text.lower():
                        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_ruRU904RU904&oq=%D0%BA%D1%83%D1%80%D1%81+%D0%B4%D0%BE%D0%BB%D0%BB&aqs=chrome.0.69i59j69i57j0l4j69i60j69i61.2360j0j7&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"}

                        full_page = requests.get(DOLLAR_RUB, headers=headers)

                        soup = BeautifulSoup(full_page.content, 'html.parser')

                        convert = soup.findAll("span", {"class": "DFlfde", "class": "SwHCTb", "data-precision": 2})
                        vk.method("messages.send", {"peer_id": event.object.peer_id, "message": "Сейчас курс доллара равен: " + convert[0].text + " рублей",
                                                    "random_id": 0})
    except Exception as E:
        time.sleep(1)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem, 2020-06-16
@b_a_y

The class is called "DFlfde SwHCTb", not "class": "DFlfde", "class": "SwHCTb". And you need to get not the value of "data-precision", but "data-value"
5ee8b6c8dbc9f500825213.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question