Update bd

This commit is contained in:
Axeten
2023-03-29 23:16:07 +03:00
committed by GitHub
parent 6a8fc8cf53
commit 709fc0d694
+6 -5
View File
@@ -8,7 +8,7 @@ connection = psycopg2.connect(host='localhost', dbname='postgres',
cursor = connection.cursor() cursor = connection.cursor()
cr_qwery = """ create table avito cr_qwery = """ create table parser
(id serial primary key, (id serial primary key,
name varchar(60), name varchar(60),
price varchar(15), price varchar(15),
@@ -17,8 +17,8 @@ cr_qwery = """ create table avito
cursor.execute(cr_qwery) cursor.execute(cr_qwery)
connection.commit() connection.commit()
driver = Service('C:\Desktop\exe\chromedriver.exe') s = Service('C:\Desktop\exe\chromedriver.exe')
browser = webdriver.Chrome(service=driver) browser = webdriver.Chrome(service=s)
browser.get('https://www.hellride.ru/catalog/zapchasti-dlya-tryukovyh-samokatov/deki') browser.get('https://www.hellride.ru/catalog/zapchasti-dlya-tryukovyh-samokatov/deki')
html_code = browser.page_source html_code = browser.page_source
soup = BeautifulSoup(html_code, 'lxml') soup = BeautifulSoup(html_code, 'lxml')
@@ -26,9 +26,10 @@ soup = BeautifulSoup(html_code, 'lxml')
name = soup.find_all('span', class_='product-card__title') name = soup.find_all('span', class_='product-card__title')
price = soup.find_all('span', class_='product-card__price') price = soup.find_all('span', class_='product-card__price')
picture = soup.find_all('img', class_='product-slider__slide-img swiper-lazy swiper-lazy-loaded') picture = soup.find_all('img', class_='product-slider__slide-img swiper-lazy swiper-lazy-loaded')
#for prices, names in zip(price, name,):
#print(f" название {names.text} ; цена: {prices.text} ")
for i in range(len(name)): for i in range(len(name)):
url = picture[i].find('img').attrs['src'] url = picture[i].attrs['src']
filename = f"C:\\Users\\Михаил\PycharmProjects\pythonProject8\\venv\Pictures\{i}.jpg" filename = f"C:\\Users\\Михаил\PycharmProjects\pythonProject8\\venv\Pictures\{i}.jpg"
wget.download(url, filename) wget.download(url, filename)
ins_qwery = f"""insert into public.Parser(name, price, picture) ins_qwery = f"""insert into public.Parser(name, price, picture)