Update DataBaze.py

This commit is contained in:
eauskova
2023-05-09 02:58:51 +03:00
committed by GitHub
parent f985f9b2d5
commit 8a4ba475d0
+21 -25
View File
@@ -4,36 +4,32 @@ from selenium.webdriver.chrome.service import Service
import psycopg2 import psycopg2
import wget import wget
browser = webdriver.Chrome(service=Service('C:\\Users\\Yekaterina\\Downloads\\chromedriver_win32.zip\\chromedriver.exe'))
browser.get('https://msk.sushi-market.com/menu/rolly')
soup = BeautifulSoup(browser.page_source, "lxml")
Name = soup.find_all(attrs={"class": "goodsBlockName device-show"})
Info = soup.find_all(attrs={"class": "goodsBlockWeight"})
Des = soup.find_all(attrs={"class": "cardsList_text"})
Price = soup.find_all(attrs={"class": "goodsBlockPrice"})
Image = soup.find_all(attrs={"class": "cardsList_img add-to-cart__img"})
connection = psycopg2.connect(host='localhost', dbname='dbdata', user='postgres', password='Q1w2e3r4') connection = psycopg2.connect(host='localhost', dbname='dbdata', user='postgres', password='Q1w2e3r4')
cursor = connection.cursor() cursor = connection.cursor()
create_q = '''CREATE TABLE Food (ID serial primary key, Name varchar(5000), Info varchar(5000), Des varchar(10000), Price varchar(6000), src varchar(1000))'''
crtable = """ create table Notebooks cursor.execute(create_q)
(id serial primary key, name varchar(500), description varchar(500), code varchar(200), price varchar(100),
picture varchar(500)) """
cursor.execute(crtable)
connection.commit() connection.commit()
s = Service('C:\\Users\\Yekaterina\\Downloads\\chromedriver_win32\\chromedriver.exe') for j in range(25):
browser = webdriver.Chrome(service=s) url = Image[j].find('img').attrs['src']
browser.get('https://www.citilink.ru/catalog/noutbuki/') tempf = f"img\\food{j}.jpg"
html_text = browser.page_source wget.download(url, tempf)
soup = BeautifulSoup(html_text, 'lxml') insert_query = f'''INSERT into public.Food(Name, Info, Des, Price, src) values ('{Name[j].text}','{Info[j].text}','{Des[j].text}', '{Price[j].text}', '{tempf}') '''
cursor.execute(insert_query)
connection.commit()
name = soup.find_all('div', class_='app-catalog-1tp0ino e1an64qs0') cursor.execute("SELECT * from Food")
description = soup.find_all('div', class_='app-catalog-1o4umte eevw8x70') print(cursor.fetchall())
code = soup.find_all('div', class_= 'app-catalog-0 e1dsj6g20')
price = soup.find_all('div', class_= 'app-catalog-0 e1dsj6g20')
picture = soup.find_all('div', class_='app-catalog-0 e1jarwcz0')
for i in range(len(name)):
url = picture[i].find('img').attrs['src']
file = f"C:\\Users\\Yekaterina\\Desktop\\baza\\pic{i}.JPG"
wget.download(url, file)
ins_qwery = f"""insert into public.Notebooks(name, description, code, price, picture)
values ('{name[i].text}', '{description[i].text}', '{code[i].text}', '{price[i].text}','{file}')"""
cursor.execute(ins_qwery)
connection.commit()
cursor.close() cursor.close()
connection.close() connection.close()