mirror of
https://github.com/KUlishevgeniy/c22712.git
synced 2026-09-24 08:00:22 +00:00
Update bdpars.py
This commit is contained in:
@@ -5,27 +5,23 @@ from selenium import webdriver
|
|||||||
from selenium.webdriver.chrome.service import Service
|
from selenium.webdriver.chrome.service import Service
|
||||||
connection = psycopg2.connect(host='localhost', dbname='postgres',
|
connection = psycopg2.connect(host='localhost', dbname='postgres',
|
||||||
user='postgres', password='Q1w2e3r4')
|
user='postgres', password='Q1w2e3r4')
|
||||||
|
|
||||||
cursor = connection.cursor()
|
cursor = connection.cursor()
|
||||||
|
|
||||||
cr_qwery = """ create table parser
|
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),
|
||||||
picture varchar(100))"""
|
picture varchar(100))"""
|
||||||
|
|
||||||
cursor.execute(cr_qwery)
|
cursor.execute(cr_qwery)
|
||||||
connection.commit()
|
connection.commit()
|
||||||
|
|
||||||
s = Service('C:\Desktop\exe\chromedriver.exe')
|
s = Service('C:\Desktop\exe\chromedriver.exe')
|
||||||
browser = webdriver.Chrome(service=s)
|
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')
|
||||||
|
name = soup.find_all('span', class_='product-card__title')
|
||||||
|
price = soup.find_all('span', class_='product-card__price')
|
||||||
|
picture = soup.find_all('img', class_='product-slider__slide-img swiper-lazy swiper-lazy-loaded')
|
||||||
|
|
||||||
name = soup.find_all(attrs={"class": "product-card__title"})
|
|
||||||
price = soup.find_all(attrs={"class": "product-card__price"})
|
|
||||||
picture = soup.find_all(attrs={"class": "product-slider__slide-img swiper-lazy swiper-lazy-loaded"})
|
|
||||||
#for prices, names in zip(price, name,):
|
#for prices, names in zip(price, name,):
|
||||||
#print(f" название {names.text} ; цена: {prices.text} ")
|
#print(f" название {names.text} ; цена: {prices.text} ")
|
||||||
for i in range(len(name)):
|
for i in range(len(name)):
|
||||||
@@ -34,12 +30,14 @@ for i in range(len(name)):
|
|||||||
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)
|
||||||
values ('{name[i].text}', '{price[i].text}', '{filename}')"""
|
values ('{name[i].text}', '{price[i].text}', '{filename}')"""
|
||||||
cursor.execute(ins_qwery)
|
cursor.execute(ins_qwery)
|
||||||
connection.commit()
|
connection.commit()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
cursor.close()
|
cursor.close()
|
||||||
|
|
||||||
connection.close()
|
connection.close()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user