From 3701d8af37121b9feace9e783130a1f6d108864a Mon Sep 17 00:00:00 2001 From: nikitin712 Date: Wed, 29 Mar 2023 18:40:10 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=BC=D0=B0=D1=88=D0=BD=D0=B5?= =?UTF-8?q?=D0=B5=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5=201=20(?= =?UTF-8?q?=D0=9F=D0=B0=D1=80=D1=81=D0=B8=D0=BD=D0=B3)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Задания/task1/nikitin/test2.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/Задания/task1/nikitin/test2.py b/Задания/task1/nikitin/test2.py index 23b8205..ccb97a6 100644 --- a/Задания/task1/nikitin/test2.py +++ b/Задания/task1/nikitin/test2.py @@ -3,6 +3,7 @@ from selenium import webdriver from selenium.webdriver.chrome.service import Service import psycopg2 import wget +import time connection = psycopg2.connect(host='localhost', dbname='dbdata', user='postgres', password='Q1w2e3r4') cursor = connection.cursor() @@ -11,6 +12,7 @@ s = Service('D:\Games\data\chromedriver.exe') browser = webdriver.Chrome(service=s) browser.get('https://www.volkswagen.ru/polo/') html_text = browser.page_source +time.sleep(2) soup = BeautifulSoup(html_text, 'lxml') creat_table = """ create table Cars_volks @@ -25,17 +27,13 @@ prices = soup.find_all('div', class_='avn001-2_price-container') adresses = soup.find_all('div', class_='avn001-2_dealer-link__text') pictures = soup.find_all('div', class_='avn001-2_image image__container') -#for car_name, adress, price in zip(car_names, adresses, prices): -# print(f"Название машины:{car_name.text} | Адрес диллера: {adress.text} | Цена: {price.text} рублей") - for i in range(len(car_names)): - url = pictures[i].find('img').attrs['src'] - filename = f"c22712\\Задания\\task1\\nikitin\\img\\{i}.jpg" -# wget.download(url, filename) представим что картинки скачались:) - + url = pictures[i].find('img')['src'] + filename = f"C:\\Users\\Пользователь\\OneDrive\\Рабочий стол\\pycharm\\c22712\\Задания\\task1\\nikitin\\img\{i}.jpg" + wget.download(url, filename) insert_qwery = f"""INSERT INTO public.Cars_volks(car_name, price, adress, scr) VALUES ('{car_names[i].text}', '{prices[i].text}', '{adresses[i].text}', '{filename}')"""; - cursor.execute(insert_qwery) + #cursor.execute(insert_qwery) connection.commit() cursor.close()