mirror of
https://github.com/KUlishevgeniy/c22712.git
synced 2026-09-23 23:50:21 +00:00
Домашнее задание 1 (Парсинг)
This commit is contained in:
@@ -3,6 +3,7 @@ from selenium import webdriver
|
|||||||
from selenium.webdriver.chrome.service import Service
|
from selenium.webdriver.chrome.service import Service
|
||||||
import psycopg2
|
import psycopg2
|
||||||
import wget
|
import wget
|
||||||
|
import time
|
||||||
|
|
||||||
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()
|
||||||
@@ -11,6 +12,7 @@ s = Service('D:\Games\data\chromedriver.exe')
|
|||||||
browser = webdriver.Chrome(service=s)
|
browser = webdriver.Chrome(service=s)
|
||||||
browser.get('https://www.volkswagen.ru/polo/')
|
browser.get('https://www.volkswagen.ru/polo/')
|
||||||
html_text = browser.page_source
|
html_text = browser.page_source
|
||||||
|
time.sleep(2)
|
||||||
soup = BeautifulSoup(html_text, 'lxml')
|
soup = BeautifulSoup(html_text, 'lxml')
|
||||||
|
|
||||||
creat_table = """ create table Cars_volks
|
creat_table = """ create table Cars_volks
|
||||||
@@ -25,17 +27,13 @@ prices = soup.find_all('div', class_='avn001-2_price-container')
|
|||||||
adresses = soup.find_all('div', class_='avn001-2_dealer-link__text')
|
adresses = soup.find_all('div', class_='avn001-2_dealer-link__text')
|
||||||
pictures = soup.find_all('div', class_='avn001-2_image image__container')
|
pictures = soup.find_all('div', class_='avn001-2_image image__container')
|
||||||
|
|
||||||
#for car_name, adress, price in zip(car_names, adresses, prices):
|
|
||||||
# print(f"Название машины:{car_name.text} | Адрес диллера: {adress.text} | Цена: {price.text} рублей")
|
|
||||||
|
|
||||||
for i in range(len(car_names)):
|
for i in range(len(car_names)):
|
||||||
url = pictures[i].find('img').attrs['src']
|
url = pictures[i].find('img')['src']
|
||||||
filename = f"c22712\\Задания\\task1\\nikitin\\img\\{i}.jpg"
|
filename = f"C:\\Users\\Пользователь\\OneDrive\\Рабочий стол\\pycharm\\c22712\\Задания\\task1\\nikitin\\img\{i}.jpg"
|
||||||
# wget.download(url, filename) представим что картинки скачались:)
|
wget.download(url, filename)
|
||||||
|
|
||||||
insert_qwery = f"""INSERT INTO public.Cars_volks(car_name, price, adress, scr)
|
insert_qwery = f"""INSERT INTO public.Cars_volks(car_name, price, adress, scr)
|
||||||
VALUES ('{car_names[i].text}', '{prices[i].text}', '{adresses[i].text}', '{filename}')""";
|
VALUES ('{car_names[i].text}', '{prices[i].text}', '{adresses[i].text}', '{filename}')""";
|
||||||
cursor.execute(insert_qwery)
|
#cursor.execute(insert_qwery)
|
||||||
connection.commit()
|
connection.commit()
|
||||||
|
|
||||||
cursor.close()
|
cursor.close()
|
||||||
|
|||||||
Reference in New Issue
Block a user