From a0e99cb827d35a744b847c6f6b1393a68e2aa598 Mon Sep 17 00:00:00 2001 From: ada-dmitry Date: Sun, 26 Mar 2023 20:00:13 +0300 Subject: [PATCH] v1 --- Programming/other/Vova1.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Programming/other/Vova1.py diff --git a/Programming/other/Vova1.py b/Programming/other/Vova1.py new file mode 100644 index 0000000..6da424c --- /dev/null +++ b/Programming/other/Vova1.py @@ -0,0 +1,33 @@ +from bs4 import BeautifulSoup +from selenium import webdriver +from selenium.webdriver.chrome.service import Service +import psycopg2 +import wget + +browser = webdriver.Chrome(service=Service('C:\Desktop\exe\chromedriver.exe')) +browser.get('https://flawery.ru/moscow/bouquets/event-yanvary25/') +soup = BeautifulSoup(browser.page_source, "lxml") +Name = soup.find_all(attrs={"class": "catalog_title"}) +Price = soup.find_all(attrs={"class": "catalog_price_now"}) +Delivery_Time = soup.find_all(attrs={"class": "catalog_express"}) +Delivery_Price = soup.find_all(attrs={"class": "catalog_delivery"}) +Image = soup.find_all('div', class_="catalog_item catalog_item_popup") + +connection = psycopg2.connect(host='localhost', dbname='FHWDB', user='postgres', password='Q1w2e3r4') +cursor = connection.cursor() +create_q = '''CREATE TABLE Parse +(ID serial primary key, Name varchar(100), Price varchar(9), Delivery_Time varchar(25), Delivery_Price varchar(20), src varchar(110))''' +cursor.execute(create_q) +connection.commit() + +for j in range(10): + url = 'https://flawery.ru'+Image[j].find('a').find('img').attrs['src'] + print(url) + tempf = f'C:\\Users\\user\\Desktop\\FHWDB{j}.jpg' + wget.download(url, tempf) + insert_query = f'''INSERT into public.Parse(Name, Price, Delivery_Time, Delivery_Price, scr) values ('{Name[j].text}', '{Price[j].text}', '{Delivery_Time[j].text}', '{Delivery_Price[j].text}', '{tempf}') ''' + cursor.execute(insert_query) + connection.commit() + +cursor.close() +connection.close() \ No newline at end of file