From 3647eca03b30b62eb4128c5d4fe0522e76a28cc8 Mon Sep 17 00:00:00 2001 From: rus2004 Date: Mon, 22 May 2023 23:49:54 +0300 Subject: [PATCH] =?UTF-8?q?=D1=80=D0=B0=D0=B1=D0=BE=D1=87=D0=B0=D1=8F=20?= =?UTF-8?q?=D0=B1=D0=B4=20=D1=81=20=D1=81=D0=BF=D0=B0=D1=80=D1=88=D0=B5?= =?UTF-8?q?=D0=BD=D0=BD=D1=8B=D0=BC=D0=B8=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B?= =?UTF-8?q?=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Задания/task1/Samigullin/main.py | 44 ++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Задания/task1/Samigullin/main.py diff --git a/Задания/task1/Samigullin/main.py b/Задания/task1/Samigullin/main.py new file mode 100644 index 0000000..10ac7a9 --- /dev/null +++ b/Задания/task1/Samigullin/main.py @@ -0,0 +1,44 @@ +from bs4 import BeautifulSoup +from selenium.webdriver import Chrome +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() + + + +s = Service('C:\data\hrome\chromedriver.exe') +browser = webdriver.Chrome(service=s) +browser.get('https://blog.okko.tv/selections/vremya-letit-bystro-10-filmov-kotorye-smotryatsya-na-odnom-dykhanii') +time.sleep (20) +html_text = browser.page_source +soup = BeautifulSoup(html_text, 'lxml') + +creat_table="""create table notes + (id serial primary key, name varchar(150), + price varchar(150), + scr varchar(150))""" +cursor.execute(creat_table) +connection.commit() + + +names= soup.find_all('h2', class_="film-card-title") +prices = soup.find_all('span', class_="f-c-rating") +pictures = soup.find_all('figure', class_="wp-block-image size-large") +for i in range(len(names)): + url = pictures[i].find('img')['src'] + filename = f"C:\\Users\\rusta\\OneDrive\\Рабочий стол\\pictures111\\{i}.jpg" + wget.download(url, filename) + + insert_qwery = """INSERT INTO public.notes(name, price, scr) + VALUES( %s, %s, %s);""" + record_to_insert = (names[i].text, prices[i].text, filename) + cursor.execute(insert_qwery, record_to_insert) + connection.commit() + +cursor.close() +connection.close()