Спарсил я короче данные с сайта и записал в json, все прекрасно. Начал пробовать считать это json, для вывода в tg бота, и тут сюрприз :
Task exception was never retrieved
future: <Task finished name='Task-13' coro=<Dispatcher._process_polling_updates() done, defined at D:\projects\fun_pay\venv\lib\site-packages\aiogram\dispatcher\dispatcher.py:407> exception=JSONDecodeError('Extra data: line 25867 column 2 (char 1086688)')>
Traceback (most recent call last):
File "D:\projects\fun_pay\venv\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 415, in _process_polling_updates
for responses in itertools.chain.from_iterable(await self.process_updates(updates, fast)):
File "D:\projects\fun_pay\venv\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 235, in process_updates
return await asyncio.gather(*tasks)
File "D:\projects\fun_pay\venv\lib\site-packages\aiogram\dispatcher\handler.py", line 116, in notify
response = await handler_obj.handler(*args, **partial_data)
File "D:\projects\fun_pay\venv\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 256, in process_update
return await self.message_handlers.notify(update.message)
File "D:\projects\fun_pay\venv\lib\site-packages\aiogram\dispatcher\handler.py", line 116, in notify
response = await handler_obj.handler(*args, **partial_data)
File "D:\projects\fun_pay\test1.py", line 38, in start
data = json.load(file)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1520.0_x64__qbz5n2kfra8p0\lib\json\__init__.py", line 293, in load
return loads(fp.read(),
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1520.0_x64__qbz5n2kfra8p0\lib\json\__init__.py", line 346, in loads
return _default_decoder.decode(s)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1520.0_x64__qbz5n2kfra8p0\lib\json\decoder.py", line 340, in decode
raise JSONDecodeError("Extra data", s, end)
json.decoder.JSONDecodeError: Extra data: line 25867 column 2 (char 1086688)
___________________________________________________________________________________________
from aiogram import Bot, Dispatcher, executor, types
from aiogram.dispatcher.filters import Text
from aiogram.utils.markdown import hbold, hlink
from main import get_pages
import json
import time
bot = Bot(token='5454621758:AAHgTLqtbCW3xxO-u5QGOs2l1DLTd2svuw0', parse_mode=types.ParseMode.HTML)
dp = Dispatcher(bot)
@dp.message_handler(commands='start')
async def start(message: types.Message):
start_buttons = ['1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'10'
]
keyboard = types.ReplyKeyboardMarkup(resize_keyboard=True)
keyboard.add(*start_buttons)
await message.answer("Выберите категорию", reply_markup=keyboard)
@dp.message_handler(Text(equals='1'))
async def start(message: types.Message):
await message.answer('Так, так, так... Секундочку....')
get_pages()
with open('data/ak.json', encoding='utf-8') as file:
data = json.load(file)
for index, item in enumerate(data):
card = f'{hlink(item.get("Ссылка на офер"))}\n'\
f'{hbold("Краткое описание: ")}{item.get("Краткое описание")}\n' \
f'{hbold("Продавец: ")}{item.get("Продавец")}\n' \
f'{hbold("Сколько находится на сайте: ")}{item.get("Сколько находится на сайте")}\n' \
f'{hbold("Цена: ")}{item.get("Цена")}\n'
if index % 10 == 0:
time.sleep(3)
await message.answer(card)
def main():
executor.start_polling(dp)
if __name__ == '__main__':
main()
_____________________________________________________________________________________________________________