mirror of
https://github.com/KUlishevgeniy/c22712.git
synced 2026-09-23 23:50:21 +00:00
Merge remote-tracking branch 'origin/master'
# Conflicts: # .idea/workspace.xml
This commit is contained in:
@@ -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"
|
||||
|
||||
for button in buttons:
|
||||
# выводим текст каждого тега
|
||||
print(button.text)
|
||||
|
||||
# от сердца и почек
|
||||
# дарю вам питончик
|
||||
# made by perfecto
|
||||
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")
|
||||
|
||||
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