Task 2
@@ -0,0 +1 @@
|
|||||||
|
Work with driver.py
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
<changelist name="Uncommitted_changes_before_Update_at_15_02_2023_1_03_[Changes]" date="1676412217607" recycled="false" toDelete="true">
|
||||||
|
<option name="PATH" value="$PROJECT_DIR$/.idea/shelf/Uncommitted_changes_before_Update_at_15_02_2023_1_03_[Changes]/shelved.patch" />
|
||||||
|
<option name="DESCRIPTION" value="Uncommitted changes before Update at 15.02.2023 1:03 [Changes]" />
|
||||||
|
</changelist>
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="PYTHON_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<settings>
|
||||||
|
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||||
|
<version value="1.0" />
|
||||||
|
</settings>
|
||||||
|
</component>
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11" project-jdk-type="Python SDK" />
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/Gusev.iml" filepath="$PROJECT_DIR$/.idea/Gusev.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$/../../.." vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
@@ -1 +0,0 @@
|
|||||||
print('Hello, World!')
|
|
||||||
|
After Width: | Height: | Size: 30 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 25 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 21 KiB |
|
After Width: | Height: | Size: 29 KiB |
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 21 KiB |
|
After Width: | Height: | Size: 26 KiB |
|
After Width: | Height: | Size: 36 KiB |
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 25 KiB |
|
After Width: | Height: | Size: 20 KiB |
|
After Width: | Height: | Size: 30 KiB |
|
After Width: | Height: | Size: 34 KiB |
|
After Width: | Height: | Size: 30 KiB |
|
After Width: | Height: | Size: 26 KiB |
|
After Width: | Height: | Size: 34 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 24 KiB |
|
After Width: | Height: | Size: 24 KiB |
|
After Width: | Height: | Size: 25 KiB |
|
After Width: | Height: | Size: 25 KiB |
|
After Width: | Height: | Size: 26 KiB |
@@ -0,0 +1,61 @@
|
|||||||
|
from bs4 import BeautifulSoup # подключение к библиотекам парсинга и работы с базами данных
|
||||||
|
import psycopg2
|
||||||
|
from wget import download
|
||||||
|
from selenium import webdriver
|
||||||
|
from selenium.webdriver.chrome.service import Service
|
||||||
|
|
||||||
|
S = Service("D:\Драйвер\chromedriver.exe")
|
||||||
|
browser = webdriver.Chrome(service=S)
|
||||||
|
browser.get('https://ultrasport.ru/catalog/velosipedy/gornye_velosipedy/') # подключение к сайту, с которого будем парсить данные
|
||||||
|
html_text = browser.page_source # сохранение html кода страницы в переменную html_text
|
||||||
|
soup = BeautifulSoup(html_text, 'lxml') # преобразуем код в дерево объектов
|
||||||
|
|
||||||
|
info = soup.find_all('div', class_="inner_wrap TYPE_1") # поиск всех описывающих товар общих тэгов
|
||||||
|
|
||||||
|
try:
|
||||||
|
connection = psycopg2.connect( # подключение к базе данных
|
||||||
|
host='localhost',
|
||||||
|
dbname='Bicycles',
|
||||||
|
user='postgres',
|
||||||
|
password='Q1w2e3r4'
|
||||||
|
)
|
||||||
|
connection.autocommit = True # настройка автоматического комита
|
||||||
|
|
||||||
|
with connection.cursor() as cursor: # создание таблицы в базе данных
|
||||||
|
cursor.execute(
|
||||||
|
"""CREATE TABLE bikes(
|
||||||
|
id serial PRIMARY KEY,
|
||||||
|
bike_name varchar(100) NOT NULL,
|
||||||
|
bike_view varchar(1000) NOT NULL,
|
||||||
|
bike_price varchar(100) NOT NULL,
|
||||||
|
bike_availability varchar(100) NOT NULL);
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
with connection.cursor() as cursor: # заполнение таблицы данным, которые мы спарсили с сайта
|
||||||
|
for i, item in enumerate(info):
|
||||||
|
name = item.find('a', class_="dark_link js-notice-block__title option-font-bold font_sm").text.strip()
|
||||||
|
price = item.find('div', class_="price only_price font-bold font_mxs").text.strip()
|
||||||
|
enough = item.find('span', class_="value font_sxs").text.strip()
|
||||||
|
p_src = item.find('img', class_="lazy img-responsive").get("src")
|
||||||
|
download(p_src, f"images/{i+1}.jpg")
|
||||||
|
cursor.execute(
|
||||||
|
f"""INSERT INTO public.bikes(
|
||||||
|
bike_name, bike_view, bike_price, bike_availability)
|
||||||
|
VALUES
|
||||||
|
('{name}','images/{i+1}.jpg','{price}','{enough}');"""
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
except Exception as _ex: # обработка ошибок
|
||||||
|
print("[INFO] ERROR", _ex)
|
||||||
|
|
||||||
|
finally: # завершение подключения
|
||||||
|
if connection:
|
||||||
|
connection.close()
|
||||||
|
print("[INFO] Connection closed")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Проверка работы.
|
||||||