first commit
This commit is contained in:
commit
be2a0e947b
Binary file not shown.
|
|
@ -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
|
||||
|
|
@ -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))
|
||||
|
||||
Loading…
Reference in New Issue