🤘Сливаю вам скрипт бота который делает скрин сайта по ссылке
Код Python:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
import logging from aiogram import Bot, Dispatcher, executor, types from aiogram.dispatcher.filters import Text from aiogram.contrib.fsm_storage.memory import MemoryStorage from aiogram.dispatcher.filters.state import StatesGroup, State from aiogram.utils.exceptions import Throttled from aiogram.dispatcher import FSMContext from aiogram.types import CallbackQuery, Message, InputFile import re from selenium import webdriver from webdriver_manager.chrome import ChromeDriverManager from selenium.webdriver.chrome.options import Options bot = Bot(token="") #Тут токен storage = MemoryStorage() dp = Dispatcher(bot, storage=storage) logging.basicConfig(level=logging.INFO) @dp.message_handler(content_types="text") async def parser(message: types.Message): pattern = r'(http[s]?://)?(www\.)?[\w.]+\.[\w]+' match = re.search(pattern, message.text) if match: print(match.group()) keyboard = types.InlineKeyboardMarkup() buttons = [ types.InlineKeyboardButton(text="Создать скриншот!", callback_data=f"{match.group()}") ] keyboard.add(*buttons) await message.reply(f"В сообщении обнаружена ссылка!", reply_markup=keyboard) @dp.callback_query_handler() async def process_callback_button(callback_query: CallbackQuery): action = callback_query. print(action) messages = callback_query.message await messages.edit_text("Запускаю селениум...") options = Options() options.add_argument('--headless') options.add_argument('--disable-gpu') options.add_argument('--proxy-server=socks5://тутпрокси') #Тут прокси driver = webdriver.Chrome(executable_path=ChromeDriverManager().install(), options=options) await messages.edit_text("Делаю скриншот...") driver.get(action) driver.save_screenshot(f"screen/{callback_query.message.chat.id}.png") driver.quit() await messages.delete() photo = InputFile(f'screen/{callback_query.message.chat.id}.png') await bot.send_photo(callback_query.message.chat.id, photo, f"Скриншот успешно сделан!\nСайт: {action}") if name == "__main__": executor.start_polling(dp, skip_updates=True) |