mirror of
https://github.com/KUlishevgeniy/c22712.git
synced 2026-09-24 08:00:22 +00:00
Merge remote-tracking branch 'origin/master'
# Conflicts: # .idea/workspace.xml
This commit is contained in:
Generated
+1
-1
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9" project-jdk-type="Python SDK" />
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11" project-jdk-type="Python SDK" />
|
||||
</project>
|
||||
Generated
+4
-28
@@ -4,10 +4,7 @@
|
||||
<option name="autoReloadType" value="SELECTIVE" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="e5615680-c090-497d-a104-1337ed85f850" name="Changes" comment="for parsing">
|
||||
<change afterPath="$PROJECT_DIR$/Задания/task1/Kluchinskaya1/parsing_in_bd.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
</list>
|
||||
<list default="true" id="e5615680-c090-497d-a104-1337ed85f850" name="Changes" comment="parser" />
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||
@@ -25,6 +22,7 @@
|
||||
</component>
|
||||
<component name="Git.Settings">
|
||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||
<option name="UPDATE_TYPE" value="REBASE" />
|
||||
</component>
|
||||
<component name="MarkdownSettingsMigration">
|
||||
<option name="stateVersion" value="1" />
|
||||
@@ -35,11 +33,6 @@
|
||||
<option name="hideEmptyMiddlePackages" value="true" />
|
||||
<option name="showLibraryContents" value="true" />
|
||||
</component>
|
||||
<component name="PropertiesComponent">
|
||||
<property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
|
||||
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
|
||||
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
|
||||
</component>
|
||||
<component name="RunManager">
|
||||
<configuration name="main" type="PythonConfigurationType" factoryName="Python" nameIsGenerated="true">
|
||||
<module name="22712" />
|
||||
@@ -109,21 +102,7 @@
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1676934066947</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00006" summary="for parsing">
|
||||
<created>1677183215124</created>
|
||||
<option name="number" value="00006" />
|
||||
<option name="presentableId" value="LOCAL-00006" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1677183215124</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00007" summary="for parsing">
|
||||
<created>1677183242833</created>
|
||||
<option name="number" value="00007" />
|
||||
<option name="presentableId" value="LOCAL-00007" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1677183242833</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="8" />
|
||||
<option name="localTasksCounter" value="6" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="TypeScriptGeneratedFilesManager">
|
||||
@@ -139,14 +118,11 @@
|
||||
</entry>
|
||||
</map>
|
||||
</option>
|
||||
<option name="oldMeFiltersMigrated" value="true" />
|
||||
</component>
|
||||
<component name="VcsManagerConfiguration">
|
||||
<MESSAGE value="Первый коммит" />
|
||||
<MESSAGE value="parser" />
|
||||
<MESSAGE value=" for parsing" />
|
||||
<MESSAGE value="for parsing" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="for parsing" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="parser" />
|
||||
</component>
|
||||
<component name="XDebuggerManager">
|
||||
<breakpoint-manager>
|
||||
|
||||
@@ -1,16 +1,23 @@
|
||||
# This is a sample Python script.
|
||||
from bs4 import BeautifulSoup
|
||||
from selenium.webdriver import Chrome
|
||||
from selenium import webdriver
|
||||
from selenium.webdriver.chrome.service import Service
|
||||
import time
|
||||
|
||||
# Press Shift+F10 to execute it or replace it with your code.
|
||||
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
|
||||
# Selenium - библиотека для автоматизации действий веб браузера, скрапинга
|
||||
# запускаем браузер
|
||||
s = Service('C:\data\chrome\chromedriver.exe')
|
||||
browser = webdriver.Chrome(service=s)
|
||||
browser.get('https://www.wildberries.ru/catalog/muzhchinam/odezhda/futbolki-i-mayki?bid=3b73ce5a-8eba-45a1-b9b2-0723f7592eac#c145658286')
|
||||
time.sleep (10)#задержка для ввода капчи
|
||||
html_text = browser.page_source
|
||||
soup = BeautifulSoup(html_text, 'lxml')
|
||||
films=soup.find_all('div', class_='/games/the-elder-scrolls-v-skyrim/')
|
||||
ratings = soup.find_all('div', class_='KnbCardMark_label__hg6Pg tv-series-mark KnbCardMark_isGreen__G_FLl')
|
||||
for film, rating in zip(films, ratings):
|
||||
print(f"Игра:{film.text} | Рейтинг:{rating.text}")
|
||||
|
||||
|
||||
def print_hi(name):
|
||||
# Use a breakpoint in the code line below to debug your script.
|
||||
print(f'Hi, {name}') # Press Ctrl+F8 to toggle the breakpoint.
|
||||
|
||||
|
||||
# Press the green button in the gutter to run the script.
|
||||
if __name__ == '__main__':
|
||||
print_hi('PyCharm')
|
||||
|
||||
# See PyCharm help at https://www.jetbrains.com/help/pycharm/
|
||||
# Это пример парсинга. Вам необходимо спарсить 1 страницу каталога любого сайта на выбор.
|
||||
#сайты не должны повторяться
|
||||
# Спарсить необходимо только Заголовки и описание.
|
||||
@@ -1 +0,0 @@
|
||||
Тестовый вап
|
||||
@@ -0,0 +1,42 @@
|
||||
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='PythonDB', user='postgres', password='Q1w2e3r4')
|
||||
|
||||
cursor = connection.cursor()
|
||||
|
||||
creat_qwery = """ create table Parser
|
||||
(id serial primary key, page_name varchar(100), price varchar(10), priceDis varchar(30), mark varchar(10), scr varchar(100))"""
|
||||
|
||||
cursor.execute(creat_qwery)
|
||||
connection.commit()
|
||||
|
||||
driver = Service('D:\teach\Prog\chromedriver.exe')
|
||||
browser = webdriver.Chrome(service=driver)
|
||||
browser.get('https://amwine.ru/catalog/igristoe_vino_i_shampanskoe/igristoe_vino/')
|
||||
html_code = browser.page_source
|
||||
b_soup = BeautifulSoup(html_code, 'lxml')
|
||||
name = b_soup.find_all('a', class_="catalog-list-item__title js-product-detail-link")
|
||||
price = b_soup.find_all('span', class_="middle_price")
|
||||
priceDis = b_soup.find_all('span', class_="baseoldprice")
|
||||
mark = b_soup.find_all('span', class_="product-rating__rating")
|
||||
pictures = b_soup.find_all('div', class_="catalog-list-item__img-wrapper")
|
||||
|
||||
for i in range(15):
|
||||
url = 'https://amwine.ru'+pictures[i].find('a').find('img').attrs['data-src']
|
||||
filename = f"Programming\\23.03\img\{i}.jpg"
|
||||
print(filename)
|
||||
wget.download(url, filename)
|
||||
ins_qwery = f"""insert into public.Parser(page_name, price, priceDis, mark, scr) values ('{name[i].text}', '{price[i].text}', '{priceDis[i].text}', '{mark[i].text}', '{filename}')"""
|
||||
cursor.execute(ins_qwery)
|
||||
connection.commit()
|
||||
|
||||
|
||||
|
||||
|
||||
cursor.close()
|
||||
|
||||
connection.close()
|
||||
@@ -1,3 +1,6 @@
|
||||
|
||||
#Вариант с пары
|
||||
'''
|
||||
from bs4 import BeautifulSoup
|
||||
from selenium import webdriver
|
||||
from selenium.webdriver.chrome.service import Service
|
||||
@@ -10,9 +13,27 @@ html_text = browser.page_source
|
||||
time.sleep(20)
|
||||
soup = BeautifulSoup(html_text, 'lxml')
|
||||
films = soup.find_all('div', class_='base-movie-main-info_mainInfo__ZL_u3')
|
||||
'''
|
||||
|
||||
print(soup)
|
||||
print(films)
|
||||
'''
|
||||
|
||||
for film in films:
|
||||
print(film.text)
|
||||
'''
|
||||
#Домашка
|
||||
from bs4 import BeautifulSoup
|
||||
from selenium import webdriver
|
||||
from selenium.webdriver.chrome.service import Service
|
||||
|
||||
driver = Service('D:\teach\Prog\chromedriver.exe')
|
||||
browser = webdriver.Chrome(service=driver)
|
||||
browser.get('https://hmbrussia.ru/regional-office/')
|
||||
html_code = browser.page_source
|
||||
b_soup = BeautifulSoup(html_code, 'lxml')
|
||||
name = b_soup.find_all('div', class_="ps-xl-3 ms-xl-3")
|
||||
|
||||
print(b_soup)
|
||||
print(name)
|
||||
|
||||
for i in name:
|
||||
print(i.text)
|
||||
|
||||
@@ -8,6 +8,7 @@ browser.get('https://www.rftoday.ru/_vse_zagolovki2')
|
||||
html_text = browser.page_source
|
||||
soup = BeautifulSoup(html_text, 'lxml')
|
||||
infos = soup.find_all(attrs={"class": "title"})
|
||||
revs = soup.find_all(attrs={"class": "source"})
|
||||
#print(infos[0].text) - если нужно вывести только n-ый заголовок
|
||||
for info in infos:
|
||||
print(info.text)#Вывод всех заголовков новостей страницы 1
|
||||
for info, rev in zip(infos, revs):
|
||||
print(f"{info.text} ; Источник: {rev.text}")#Вывод всех заголовков новостей и их источников со страницы 1
|
||||
@@ -0,0 +1,12 @@
|
||||
from bs4 import BeautifulSoup
|
||||
from selenium import webdriver
|
||||
from selenium.webdriver.chrome.service import Service
|
||||
from time import sleep
|
||||
s = Service("C:\Driver\chromedriver.exe")
|
||||
browser = webdriver.Chrome(service=s)
|
||||
browser.get("https://mephi.ru/")
|
||||
sleep(10)
|
||||
html_text = browser.page_source
|
||||
soup = BeautifulSoup(html_text, "lxml")
|
||||
serv = soup.find_all("div", class_="views-field views-field-title menu-item menu-item-10702")
|
||||
print(serv[0].text)
|
||||
@@ -4,9 +4,9 @@ from selenium.webdriver.chrome.service import Service
|
||||
|
||||
s = Service("E:\data\chromedriver.exe")
|
||||
browser = webdriver.Chrome(service=s)
|
||||
browser.get("https://www.litres.ru/fedor-dostoevskiy/prestuplenie-i-nakazanie/")
|
||||
browser.get("https://ria.ru/")
|
||||
html_text = browser.page_source
|
||||
soup = BeautifulSoup(html_text, 'lxml')
|
||||
books = soup.find_all('div', class_='biblio_book_descr')
|
||||
for book in books:
|
||||
print(book.text)
|
||||
news = soup.find_all('div', class_='cell cell-list')
|
||||
for new in news:
|
||||
print(new.text)
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
from bs4 import BeautifulSoup
|
||||
from selenium.webdriver import Chrome
|
||||
from selenium import webdriver
|
||||
from selenium.webdriver.chrome.service import Service
|
||||
import time
|
||||
s = Service('E:\\Downloads\\chromedriver_win32.zip\\chromedriver.exe')
|
||||
browser = webdriver.Chrome(service=s)
|
||||
browser.get('https://trial-sport.ru/gds.php?s=51516&c1=1070639&c2=1070640')
|
||||
html_text = browser.page_source
|
||||
soup = BeautifulSoup(html_text, 'lxml')
|
||||
product_name=soup.find_all('a', class_='title')
|
||||
description=soup.find_all('span', class_='description')
|
||||
for product_name, description in zip(product_name, description):
|
||||
print(f"Продукт: {product_name.text} \nОписание: {description.text}")
|
||||
print(" ")
|
||||
@@ -1 +1,14 @@
|
||||
test
|
||||
from bs4 import BeautifulSoup
|
||||
from selenium.webdriver import Chrome
|
||||
from selenium import webdriver
|
||||
from selenium.webdriver.chrome.service import Service
|
||||
import time
|
||||
s = Service('E:\\Downloads\\chromedriver_win32.zip\\chromedriver.exe')
|
||||
browser = webdriver.Chrome(service=s)
|
||||
browser.get('https://trial-sport.ru/gds.php?s=51516&c1=1070639&c2=1070640')
|
||||
html_text = browser.page_source
|
||||
soup = BeautifulSoup(html_text, 'lxml')
|
||||
bike_name=soup.find_all('a', class_='title')
|
||||
print (bike_name[0].text)
|
||||
description=soup.find_all('span', class_='description')
|
||||
print (description[0].text)
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
|
||||
from bs4 import BeautifulSoup
|
||||
from selenium import webdriver
|
||||
from selenium.webdriver.chrome.service import Service
|
||||
from time import sleep
|
||||
s = Service("С:\DATA\ChromeDriver\chromedriver.exe")
|
||||
browser = webdriver.Chrome(service=s)
|
||||
browser.get("https://www.kinopoisk.ru/lists/movies/top250/")
|
||||
sleep(15)
|
||||
browser.get("https://online.metro-cc.ru/category/sladosti-chipsy-sneki/shokolad-batonchiki?from=under_search&is_action=1")
|
||||
html_text = browser.page_source
|
||||
soup = BeautifulSoup(html_text, 'lxml')
|
||||
films = soup.find_all('div', class_="desktop-list-main-info_secondaryTitleSlot__mc0mI")
|
||||
for film in films:
|
||||
print(film.text)
|
||||
print("--------")
|
||||
products = soup.find_all('a', class_="product-card-name reset-link catalog-2-level-product-card__name style--catalog-2-level-product-card")
|
||||
prices = soup.find_all('span', class_="product-card-prices__actual color-red")
|
||||
for product,price in zip(products, prices):
|
||||
print(f"Продукт: {product.text[3:]}Цена: {price.text}")
|
||||
print("-"*100)
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1 @@
|
||||
test
|
||||
@@ -0,0 +1,14 @@
|
||||
from bs4 import BeautifulSoup
|
||||
from selenium.webdriver import Chrome
|
||||
from selenium import webdriver
|
||||
from selenium.webdriver.chrome.service import Service
|
||||
import time
|
||||
s = Service('C:\\Users\\Yekaterina\\Downloads\\chromedriver_win32\\chromedriver.exe')
|
||||
browser = webdriver.Chrome(service=s)
|
||||
browser.get('https://www.citilink.ru/catalog/noutbuki/')
|
||||
html_text = browser.page_source
|
||||
soup = BeautifulSoup(html_text, 'lxml')
|
||||
name=soup.find_all('div', class_='app-catalog-1tp0ino e1an64qs0')
|
||||
print (name[0].text)
|
||||
description=soup.find_all('div', class_='app-catalog-1o4umte eevw8x70')
|
||||
print (description[0].text)
|
||||
@@ -1,40 +1,28 @@
|
||||
# установи python, pip
|
||||
|
||||
# выполни эту команду: pip install selenium bs4 lxml
|
||||
# если ты используешь pycharm, то надо библиотеки ставить не в консоли(терминале), а в самом pycharm
|
||||
# для этого нажми "view" > "tool windows" > "python packages"
|
||||
# внизу в окне поиска ищи нужные библиотеки
|
||||
# когда найдешь, нажимай на нее, справа будет кнопка "install package", устанавливай, потом перезапусти pycharm
|
||||
|
||||
# найди версию своего браузера
|
||||
# напиши в гугле "скачать драйвер для <название и версия твоего браузера> selenium"
|
||||
# теперь все готово для запуска этого
|
||||
# помните, что сам сайт(который вы хотите парсить) может вас блокировать или заставлять проходить capture, из-за чего этот код ничего не выведет
|
||||
|
||||
from bs4 import BeautifulSoup
|
||||
from selenium import webdriver
|
||||
from selenium.webdriver.chrome.service import Service
|
||||
# импортируем всё нужное
|
||||
from wget import download
|
||||
import psycopg2 as psyc
|
||||
|
||||
s = Service("путь_до_драйвера") # в ковычках указываем полный путь до скаченного ранее драйвера
|
||||
# если ты на винде, то вместо знака "\" пиши "\\"
|
||||
|
||||
brow = webdriver.Chrome(service=s) # как будто создаем виртуальный браузер
|
||||
brow = webdriver.Chrome()
|
||||
url = "https://ikey.ru/"
|
||||
brow.get(url)
|
||||
|
||||
brow.get("https://www.revshells.com/") # получаем html код сайта и другую информацию(она нам не нужна сейчас)
|
||||
html = brow.page_source
|
||||
|
||||
html = brow.page_source # копируем html код в переменную
|
||||
soup = BeautifulSoup(html, "lxml")
|
||||
|
||||
soup = BeautifulSoup(html, "lxml") # создаем специальный парсер
|
||||
products = soup.find_all(attrs={"class": "product"})
|
||||
|
||||
buttons = soup.find_all(attrs={"class": "list-group-item list-group-item-action"})
|
||||
# получаем список всех html тегов, в которых есть атрибут "class", равный: "list-group-item list-group-item-action"
|
||||
with psyc.connect(dbname="db_for_parse", user="perfecto") as conn:
|
||||
with conn.cursor() as cursor:
|
||||
for i, product in enumerate(products):
|
||||
img_tag = product.find(attrs={"class": "imagef"}).find("img")
|
||||
title = img_tag.attrs.get("alt")
|
||||
image = url + img_tag.attrs.get("src")
|
||||
download(url + img_tag.attrs.get("src"), f"images/{i}.jpg")
|
||||
|
||||
for button in buttons:
|
||||
# выводим текст каждого тега
|
||||
print(button.text)
|
||||
|
||||
# от сердца и почек
|
||||
# дарю вам питончик
|
||||
# made by perfecto
|
||||
cursor.execute(f"insert into images(link, name) values ('{image}', '{title}')")
|
||||
|
||||
conn.commit()
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
from bs4 import BeautifulSoup
|
||||
from selenium import webdriver
|
||||
from selenium.webdriver.chrome.service import Service
|
||||
s = Service('D:\Games\data\chromedriver.exe')
|
||||
browser = webdriver.Chrome(service=s)
|
||||
browser.get('https://www.volkswagen.ru/polo/')
|
||||
html_text = browser.page_source
|
||||
soup = BeautifulSoup(html_text, 'lxml')
|
||||
car_names = soup.find_all('div', class_='avn001-2_name')
|
||||
prices = soup.find_all('div', class_='avn001-2_price-container')
|
||||
for car_name, price in zip(car_names, prices):
|
||||
print(f"Название машины:{car_name.text} | Цена: {price.text} рублей")
|
||||
Reference in New Issue
Block a user