Advertisement
1nikitas

Untitled

May 21st, 2022
690
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import asyncio
  2. from CONFIG import token_id
  3. import os
  4. import openpyxl
  5. from aiogram import Bot, Dispatcher, types, executor
  6. from aiogram.dispatcher.filters import Command
  7. from selenium import webdriver
  8. from selenium.webdriver.common.by import By
  9. import shutil
  10. import schedule
  11.  
  12. bot = Bot(token="5336241962:AAEKQ3aGoF92fl3-1SUY4U5nHH6RrfkQtT4")
  13. dp = Dispatcher(bot)
  14.  
  15. async def parser(url, time):
  16.     options = webdriver.ChromeOptions()
  17.     options.add_argument('--headless')
  18.     browser = webdriver.Chrome('chromedriver', options=options)
  19.     browser.get(url)
  20.     while True:
  21.         await asyncio.sleep(time)
  22.         try:
  23.             browser.get(url)
  24.         except Exception as err:
  25.             pass
  26.     #        print(f"Get error {err=}, {type(err)=}\n")
  27.         try:
  28.             product = browser.find_element(By.TAG_NAME, 'h1')
  29.         except Exception as err:
  30.             product = ""
  31.     #        print(f"Find element TAG  {err=}, {type(err)=}\n")
  32.         try:
  33.             price = browser.find_element(By.CLASS_NAME, 'new-price')
  34.         except Exception as err:
  35.             price = ""
  36.     #        print(f"Find element CLASS_NAME NEW  {err=}, {type(err)=}\n")
  37.         try:
  38.             old_price = browser.find_element(By.CLASS_NAME, 'price-offline__old-price')
  39.         except Exception as err:
  40.             old_price = price
  41.     #        print(f"Find element CLADD_NAME OLD  {err=}, {type(err)=}\n")
  42.         try:
  43.             product = product.text
  44.         except Exception as err:
  45.             product = 'Not Found'
  46.     #        print(f"product.text  {err=}, {type(err)=}\n")
  47.         try:
  48.             price1 = price.text.split(" ")[0]
  49.         except Exception as err:
  50.             price1 = '0'
  51.     #        print(f"price.text.split  {err=}, {type(err)=\n}")
  52.         try:
  53.             old_price1 = old_price.text.split(" ")[0]
  54.         except Exception as err:
  55.             old_price1 = '0'
  56.     #        print(f"old_price.text.split  {err=}, {type(err)=\n}")
  57.         diff = int(old_price1) - int(price1)
  58.         print(product, price1, old_price1, diff)
  59.  
  60. if __name__ == '__main__':
  61.     loop = asyncio.get_event_loop()
  62.     loop.create_task(parser("https://www.r-ulybka.ru/u-catalog/goods/312991/", 2))
  63.     loop.create_task(parser("https://www.r-ulybka.ru/u-catalog/goods/298732/", 2))
  64.     loop.create_task(parser("https://www.r-ulybka.ru/u-catalog/goods/298732/", 2))
  65.     loop.create_task(parser("https://www.r-ulybka.ru/u-catalog/goods/298732/", 2))
  66.     loop.create_task(parser("https://www.r-ulybka.ru/u-catalog/goods/298732/", 2))
  67.     loop.create_task(parser("https://www.r-ulybka.ru/u-catalog/goods/298732/", 2))
  68.     loop.create_task(parser("https://www.r-ulybka.ru/u-catalog/goods/298732/", 2))
  69.     loop.create_task(parser("https://www.r-ulybka.ru/u-catalog/goods/298732/", 2))
  70.     loop.create_task(parser("https://www.r-ulybka.ru/u-catalog/goods/312991/", 2))
  71.     loop.create_task(parser("https://www.r-ulybka.ru/u-catalog/goods/298732/", 2))
  72.     loop.create_task(parser("https://www.r-ulybka.ru/u-catalog/goods/298732/", 2))
  73.     loop.create_task(parser("https://www.r-ulybka.ru/u-catalog/goods/298732/", 2))
  74.     loop.create_task(parser("https://www.r-ulybka.ru/u-catalog/goods/298732/", 2))
  75.     loop.create_task(parser("https://www.r-ulybka.ru/u-catalog/goods/298732/", 2))
  76.     loop.create_task(parser("https://www.r-ulybka.ru/u-catalog/goods/298732/", 2))
  77.     loop.create_task(parser("https://www.r-ulybka.ru/u-catalog/goods/298732/", 2))
  78.  
  79.  
  80.  
  81.     executor.start_polling(dp)
Advertisement
RAW Paste Data Copied
Advertisement