From be2a0e947bf59ffc9f784992c42ac1e30df60844 Mon Sep 17 00:00:00 2001 From: Slava Rogozhkin Date: Tue, 15 Jul 2025 23:20:03 +0300 Subject: [PATCH] first commit --- README.md | 1 + data/bz.sqlite | Bin 0 -> 16384 bytes requirements.txt | 24 ++++++++++++ src/main.py | 97 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 122 insertions(+) create mode 100644 README.md create mode 100644 data/bz.sqlite create mode 100644 requirements.txt create mode 100644 src/main.py diff --git a/README.md b/README.md new file mode 100644 index 0000000..fdf0fd9 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +Парсер цен онлайн маркетов diff --git a/data/bz.sqlite b/data/bz.sqlite new file mode 100644 index 0000000000000000000000000000000000000000..3cca1ca0cdda655b67614cc9caf0c0c307152295 GIT binary patch literal 16384 zcmeI(zfRjg7yxiPiAX6*f?7d_3Sp@WQ8*l*Nr*d@R@oT(howV>F6Ym&8~beR3rU6! zQMXQgg}zA#9)LGtsMNVemImF@yprfC4Ch0w{n2 zD1ZVefC4CR7Xq`#dbz%_q0gq0^+QO~*d1}1&Ci9GZ+iQOJ>ziy#X--Qw{8Wl5eNwb zNL5=9v2bH6F^}vxRPW74861y5aJW`2UYXss;8qT> zt?q27RsD1qE4yHfN*-HX&;dgzfC4Ch0w{n2D1ZVefC4Ch0w{n2|GYr{{;$`5XzGUt z3ZMWApa2S>01BW03ZMWApa2S>z`YW9pcmKleAC2IrTShgRnE1_dF@NBQTGef?&e z(e@s7c3qD#ms-qJpNE6mzn={mBT2|4Bg~5@>d%ilZ35Eo!o-YX=|kF&S?ZS0%4bTM z-?H?eq!QZO)b*PZ0@}59E!ws^UDx5%%`-iTT`>hB*eDahFd%F)QE81yi;_Ns(+{Q( z%uW1Q0Hsh=1KCe*mg~BVJ9ew%cxp$T%g8Ll_7k+@mc)35QguVJ@Tf zq@IX^8fJg<=3$&p-?AKwcRCKWZJU}WfeZ1FrD|n{9;0Lc>Z5)Rgjy|C1_N)`4_YlT O{MC`GC0agRKK%&~qa)w| literal 0 HcmV?d00001 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..fe7ed94 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,24 @@ +attrs==25.3.0 +certifi==2025.7.14 +charset-normalizer==3.4.2 +configparser==7.2.0 +fake-useragent==2.2.0 +h11==0.16.0 +idna==3.10 +outcome==1.3.0.post0 +PySocks==1.7.1 +requests==2.32.4 +selenium==4.34.2 +selenium-stealth==1.0.6 +setuptools==80.9.0 +sniffio==1.3.1 +sortedcontainers==2.4.0 +SQLite4==0.1.1 +trio==0.30.0 +trio-websocket==0.12.2 +typing_extensions==4.14.1 +undetected-chromedriver==3.5.5 +urllib3==2.5.0 +websocket-client==1.8.0 +websockets==15.0.1 +wsproto==1.2.0 diff --git a/src/main.py b/src/main.py new file mode 100644 index 0000000..1d70ad4 --- /dev/null +++ b/src/main.py @@ -0,0 +1,97 @@ +#TODO: add old_price and new_price to db +#TODO: from db: +# [X] - get product +# [X] - add new product +# [ ] - format price string +# [ ] - delete product +# [ ] - update product +# [ ] - сompare product +# [ ] - recalculate id +#TODO: headless chrome with virtual display + +import sqlite3 +import time +import undetected_chromedriver as uc + +db = "test" +keys = ['id', 'url', 'product', 'old_price', 'new_price'] + +# Markets +dns_elements = ["product-card-top__title", "product-buy__price"] + +def get_db_product(_id: int): + try: + connection = sqlite3.Connection('../data/bz.sqlite') + cursor = connection.cursor() + cursor.execute(f'select * from {db} where id in ({_id})') + except FileNotFoundError: + cursor.close() + else: + product = dict(zip(keys, cursor.fetchone())) + cursor.close() + if 'product' in locals(): + return product + else: + return 1 + + +def add_db_product(_url, _product, _old_price, _new_price): + connection = sqlite3.Connection('../data/bz.sqlite') + cursor = connection.cursor() + cursor.execute(f'insert into {db} (url, name, old_price, new_price) values("{_url}", "{_product}", {_old_price}, {_new_price})') + connection.commit() + cursor.close() + return 0 + +def delete_db_product(): + pass + + +def update_db_product(): + pass + + +def recalculate_db_id(): + pass + + +def compare_product(): + pass + + +# input: _elements = [name = CLASS_NAME, price = CLASS_NAME] +# output: url_product = [ url, product = VALUE[CLASS_NAME], new_price = VALUE[CLASS_NAME]] +def get_url_product_info(_url, _elements: list): + options = uc.ChromeOptions() + #options.headless = True + options.add_argument("--window-size=1920,1080") + options.add_argument('--ignore-certificate-errors') + options.add_argument('--allow-running-insecure-content') + #options.add_argument('--headless') + + driver = uc.Chrome(use_subprocess=True, options=options) + driver.get(_url) + time.sleep(5) + + driver.save_screenshot('nowsecure.png') + + values = [] + for element in _elements: + values.append(driver.find_element(uc.By.CLASS_NAME, element).text) + + _keys = ["product", "price"] + url_product = dict(zip(_keys, values)) + url_product["url"] = _url + return url_product + + +if __name__ == "__main__": + _url = "https://www.dns-shop.ru/product/e2814125168d9c2d/provodnye-nausniki-axxa-aw-02-belyj/" + _product = "headphones" + _old_price = 50 + _new_price = 50 + _id = 3 + + #add_db_product(_url, _product, _old_price, _new_price) + print(get_db_product(5)) +