Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import asyncio
- from CONFIG import token_id
- import os
- import openpyxl
- from aiogram import Bot, Dispatcher, types, executor
- from aiogram.dispatcher.filters import Command
- from selenium import webdriver
- from selenium.webdriver.common.by import By
- import shutil
- import schedule
- bot = Bot(token="5336241962:AAEKQ3aGoF92fl3-1SUY4U5nHH6RrfkQtT4")
- dp = Dispatcher(bot)
- async def parser(url, time):
- options = webdriver.ChromeOptions()
- options.add_argument('--headless')
- browser = webdriver.Chrome('chromedriver', options=options)
- browser.get(url)
- while True:
- await asyncio.sleep(time)
- try:
- browser.get(url)
- except Exception as err:
- pass
- # print(f"Get error {err=}, {type(err)=}\n")
- try:
- product = browser.find_element(By.TAG_NAME, 'h1')
- except Exception as err:
- product = ""
- # print(f"Find element TAG {err=}, {type(err)=}\n")
- try:
- price = browser.find_element(By.CLASS_NAME, 'new-price')
- except Exception as err:
- price = ""
- # print(f"Find element CLASS_NAME NEW {err=}, {type(err)=}\n")
- try:
- old_price = browser.find_element(By.CLASS_NAME, 'price-offline__old-price')
- except Exception as err:
- old_price = price
- # print(f"Find element CLADD_NAME OLD {err=}, {type(err)=}\n")
- try:
- product = product.text
- except Exception as err:
- product = 'Not Found'
- # print(f"product.text {err=}, {type(err)=}\n")
- try:
- price1 = price.text.split(" ")[0]
- except Exception as err:
- price1 = '0'
- # print(f"price.text.split {err=}, {type(err)=\n}")
- try:
- old_price1 = old_price.text.split(" ")[0]
- except Exception as err:
- old_price1 = '0'
- # print(f"old_price.text.split {err=}, {type(err)=\n}")
- diff = int(old_price1) - int(price1)
- print(product, price1, old_price1, diff)
- if __name__ == '__main__':
- loop = asyncio.get_event_loop()
- loop.create_task(parser("https://www.r-ulybka.ru/u-catalog/goods/312991/", 2))
- loop.create_task(parser("https://www.r-ulybka.ru/u-catalog/goods/298732/", 2))
- loop.create_task(parser("https://www.r-ulybka.ru/u-catalog/goods/298732/", 2))
- loop.create_task(parser("https://www.r-ulybka.ru/u-catalog/goods/298732/", 2))
- loop.create_task(parser("https://www.r-ulybka.ru/u-catalog/goods/298732/", 2))
- loop.create_task(parser("https://www.r-ulybka.ru/u-catalog/goods/298732/", 2))
- loop.create_task(parser("https://www.r-ulybka.ru/u-catalog/goods/298732/", 2))
- loop.create_task(parser("https://www.r-ulybka.ru/u-catalog/goods/298732/", 2))
- loop.create_task(parser("https://www.r-ulybka.ru/u-catalog/goods/312991/", 2))
- loop.create_task(parser("https://www.r-ulybka.ru/u-catalog/goods/298732/", 2))
- loop.create_task(parser("https://www.r-ulybka.ru/u-catalog/goods/298732/", 2))
- loop.create_task(parser("https://www.r-ulybka.ru/u-catalog/goods/298732/", 2))
- loop.create_task(parser("https://www.r-ulybka.ru/u-catalog/goods/298732/", 2))
- loop.create_task(parser("https://www.r-ulybka.ru/u-catalog/goods/298732/", 2))
- loop.create_task(parser("https://www.r-ulybka.ru/u-catalog/goods/298732/", 2))
- loop.create_task(parser("https://www.r-ulybka.ru/u-catalog/goods/298732/", 2))
- executor.start_polling(dp)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement