From 3497a6f849373781e1da10af0ef0ea7a55eed203 Mon Sep 17 00:00:00 2001 From: ada-dmitry Date: Wed, 5 Apr 2023 09:47:13 +0300 Subject: [PATCH] ss --- Python/23.03/DB1.py | 20 +++++++++++------- .../23.03/__pycache__/config.cpython-310.pyc | Bin 0 -> 242 bytes Python/23.03/config.py | 4 ++++ 3 files changed, 16 insertions(+), 8 deletions(-) create mode 100644 Python/23.03/__pycache__/config.cpython-310.pyc create mode 100644 Python/23.03/config.py diff --git a/Python/23.03/DB1.py b/Python/23.03/DB1.py index ac16e1b..03751b1 100644 --- a/Python/23.03/DB1.py +++ b/Python/23.03/DB1.py @@ -3,8 +3,11 @@ import wget from bs4 import BeautifulSoup from selenium import webdriver from selenium.webdriver.chrome.service import Service +import config + # Парсер и загрузчик в БД//Антипенко Дмитрий -connection = psycopg2.connect(host='localhost', dbname='PythonDB', user='postgres', password='Q1w2e3r4') +connection = psycopg2.connect( + host=hostname, dbname=databname, user=username, password=passw) cursor = connection.cursor() @@ -14,19 +17,22 @@ creat_qwery = """ create table Parser cursor.execute(creat_qwery) connection.commit() -driver = Service('D:\\teach\Prog\chromedriver.exe') +driver = Service('D:\\teach\Prog\chromedriver.exe') browser = webdriver.Chrome(service=driver) -browser.get('https://amwine.ru/catalog/igristoe_vino_i_shampanskoe/igristoe_vino/') +browser.get( + 'https://amwine.ru/catalog/igristoe_vino_i_shampanskoe/igristoe_vino/') html_code = browser.page_source b_soup = BeautifulSoup(html_code, 'lxml') -name = b_soup.find_all('a', class_="catalog-list-item__title js-product-detail-link") +name = b_soup.find_all( + 'a', class_="catalog-list-item__title js-product-detail-link") price = b_soup.find_all('span', class_="middle_price") priceDis = b_soup.find_all('span', class_="baseoldprice") mark = b_soup.find_all('span', class_="product-rating__rating") pictures = b_soup.find_all('div', class_="catalog-list-item__img-wrapper") for i in range(15): - url = 'https://amwine.ru'+pictures[i].find('a').find('img').attrs['data-src'] + url = 'https://amwine.ru' + \ + pictures[i].find('a').find('img').attrs['data-src'] filename = f"Programming\\23.03\img\{i}.jpg" print(filename) wget.download(url, filename) @@ -35,8 +41,6 @@ for i in range(15): connection.commit() - - cursor.close() -connection.close() \ No newline at end of file +connection.close() diff --git a/Python/23.03/__pycache__/config.cpython-310.pyc b/Python/23.03/__pycache__/config.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..973740461cdde63de384a89d407e2ec6d8b696c0 GIT binary patch literal 242 zcmYjLK?=e!5KL@@RPg2-1VM~ik0PR;rQ$*8MWP#9vF(r3}Zp=TZGix_y;0Q=WfJPKLQ3t%p19l{%uJu#A$}~Y!S{~MAg86P^ zdEtDlm9hLVtL7@ui~WdM-o$d5DeHqQ<)xMUX_RhNw~)qEFQR={*U~2t31&)2kfK8U t5Je`!I@B1So71mP%!A1^5Le7^_jpp&mM=4eXR21s|Asqagi%I0{Q?&;K~w+$ literal 0 HcmV?d00001 diff --git a/Python/23.03/config.py b/Python/23.03/config.py new file mode 100644 index 0000000..8a59dfc --- /dev/null +++ b/Python/23.03/config.py @@ -0,0 +1,4 @@ +hostname = "localhost" +databname = "PythonDB" +username = "postgres" +passw = "Q1w2e3r4"