Merge remote-tracking branch 'origin/master'

This commit is contained in:
VladEpifanov
2023-03-26 20:15:53 +03:00
2 changed files with 84 additions and 3 deletions
+43 -3
View File
@@ -4,7 +4,9 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="e5615680-c090-497d-a104-1337ed85f850" name="Changes" comment="parser" />
<list default="true" id="e5615680-c090-497d-a104-1337ed85f850" name="Changes" comment="parser">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
@@ -33,7 +35,12 @@
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="RunManager">
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"last_opened_file_path": "C:/Users/71332/PycharmProjects/c22712"
}
}]]></component>
<component name="RunManager" selected="Python.zaparsil">
<configuration name="main" type="PythonConfigurationType" factoryName="Python" nameIsGenerated="true">
<module name="22712" />
<option name="INTERPRETER_OPTIONS" value="" />
@@ -56,6 +63,32 @@
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
<configuration name="zaparsil" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="22712" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/Задания/task1/Sukhanov" />
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/Задания/task1/Sukhanov/zaparsil.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
<option name="REDIRECT_INPUT" value="false" />
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
<recent_temporary>
<list>
<item itemvalue="Python.zaparsil" />
</list>
</recent_temporary>
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
@@ -102,7 +135,14 @@
<option name="project" value="LOCAL" />
<updated>1676934066947</updated>
</task>
<option name="localTasksCounter" value="6" />
<task id="LOCAL-00006" summary="parser">
<created>1679839777822</created>
<option name="number" value="00006" />
<option name="presentableId" value="LOCAL-00006" />
<option name="project" value="LOCAL" />
<updated>1679839777822</updated>
</task>
<option name="localTasksCounter" value="7" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
@@ -0,0 +1,41 @@
import psycopg2
import wget
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
connection = psycopg2.connect(host='localhost', dbname='dbdata', user='postgres', password='Q1w2e3r4')
cursor = connection.cursor()
cr_qwery = """ create table Parser
(id serial primary key, name varchar(100), sale varchar(30), price varchar(10), rate varchar(10), picture varchar(100))"""
#cursor.execute(cr_qwery)
connection.commit()
driver = Service('D:\GOGdriver\chromedriver.exe')
browser = webdriver.Chrome(service=driver)
browser.get('https://www.perekrestok.ru/cat/promo/10')
html_code = browser.page_source
soup = BeautifulSoup(html_code, 'lxml')
name = soup.find_all('div', class_="product-card__title")
sale = soup.find_all('div', class_="sc-kYrlTI ciSrDA product-card__badge")
price = soup.find_all('div', class_="price-new")
rate = soup.find_all('div', class_="rating-value")
picture = soup.find_all('div', class_="product-card__image-wrapper")
for i in range(15):
url = picture[i].find('img').attrs['src']
filename = f"C:\\Users\\71332\PycharmProjects\pythonProject1\\venv\Pictures\{i}.jpg"
wget.download(url, filename)
ins_qwery = f"""insert into public.Parser(name, sale, price, rate, picture) values ('{name[i].text}', '{sale[i].text}', '{price[i].text}', '{rate[i].text}', '{filename}')"""
cursor.execute(ins_qwery)
connection.commit()
cursor.close()
connection.close()