Merge remote-tracking branch 'origin/master'

This commit is contained in:
rus2004
2023-04-06 02:12:51 +03:00
4 changed files with 96 additions and 8 deletions
+44
View File
@@ -0,0 +1,44 @@
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from time import sleep
import psycopg2
s = Service("C:\Driver\chromedriver.exe")
browser = webdriver.Chrome(service=s)
browser.get("https://drivenew.ru/layfkhaki/besplatno/top-10-vinodelcheskikh-khozyaystv-krasnodarskogo-kraya/")
sleep(1)
html_text = browser.page_source
soup = BeautifulSoup(html_text, "lxml")
name = soup.find_all("h2")
contacts = soup.find_all("div", class_="article-info")
address = []
number = []
for element in contacts:
a = element.find_all("p")[1]
n = element.find_all("p")[2]
address.append(a)
number.append(n)
pic = soup.find("div", class_="white-bg white-bg-text box-15-new").find_all("img")
picture = []
url = "https://drivenew.ru"
for i in pic:
p = url + i.attrs.get("src")
picture.append(p)
connection = psycopg2.connect(host='localhost', dbname='dbdata', user='postgres', password='Q1w2e3r4t5')
cursor = connection.cursor()
create = """create table Distilleries
(id serial primary key , Name varchar(100), Place varchar(200), Contacts varchar(100), ImageLink varchar(80));"""
cursor.execute(create)
connection.commit()
for j in range(10):
qwery = f"insert into public.distilleries(Name, Place, Contacts, ImageLink) values('{name[j].text.strip()}', '{address[j].text.strip()}', '{number[j].text.strip()}', '{picture[j]}')"
cursor.execute(qwery)
connection.commit()
cursor.execute('select * from Distilleries')
print(cursor.fetchall())
cursor.close()
connection.close()
+44
View File
@@ -0,0 +1,44 @@
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from time import sleep
import psycopg2
s = Service("C:\Driver\chromedriver.exe")
browser = webdriver.Chrome(service=s)
browser.get("https://drivenew.ru/layfkhaki/besplatno/top-10-vinodelcheskikh-khozyaystv-krasnodarskogo-kraya/")
sleep(1)
html_text = browser.page_source
soup = BeautifulSoup(html_text, "lxml")
name = soup.find_all("h2")
contacts = soup.find_all("div", class_="article-info")
address = []
number = []
for element in contacts:
a = element.find_all("p")[1]
n = element.find_all("p")[2]
address.append(a)
number.append(n)
pic = soup.find("div", class_="white-bg white-bg-text box-15-new").find_all("img")
picture = []
url = "https://drivenew.ru"
for i in pic:
p = url + i.attrs.get("src")
picture.append(p)
connection = psycopg2.connect(host='localhost', dbname='dbdata', user='postgres', password='Q1w2e3r4t5')
cursor = connection.cursor()
create = """create table Distilleries
(id serial primary key , Name varchar(100), Place varchar(200), Contacts varchar(100), ImageLink varchar(80));"""
cursor.execute(create)
connection.commit()
for j in range(10):
qwery = f"insert into public.distilleries(Name, Place, Contacts, ImageLink) values('{name[j].text.strip()}', '{address[j].text.strip()}', '{number[j].text.strip()}', '{picture[j]}')"
cursor.execute(qwery)
connection.commit()
cursor.execute('select * from Distilleries')
print(cursor.fetchall())
cursor.close()
connection.close()
+3 -3
View File
@@ -25,17 +25,17 @@ price = soup.find_all('span', class_="price")
priceDis = soup.find_all('span', class_="discount")
pictures = soup.find_all('div', class_="img")
for i in range(20):
url = 'https://trial-sport.ru/gds.php?s=51516&c1=1070639&c2=1070640'+pictures[i].find('a').find('img')['src']
filename = f"E:\Downloads\parcing\img\{i}.jpg"
wget.download(url, filename)
ins_qwery = f"""insert into public.Parser(product_name, description, price, priceDis, scr)
VALUES ('{product_name[i].text}','{description[i].text}', '{price[i].text}', '{priceDis[i].text}', '{filename}')"""
cursor.execute(f"""insert into Parsing (product_name, description, price, priceDis, scr)
VALUES ('{product_name[i].text}','{description[i].text}', '{price[i].text}', '{priceDis[i].text}', '{filename}')""")
connection.commit()
cursor.close()
connection.close()
@@ -1,5 +1,5 @@
import psycopg2
import wget
import psycopg2
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
@@ -23,9 +23,9 @@ browser.get('https://www.hellride.ru/catalog/zapchasti-dlya-tryukovyh-samokatov/
html_code = browser.page_source
soup = BeautifulSoup(html_code, 'lxml')
name = soup.find_all('span', class_='product-card__title')
price = soup.find_all('span', class_='product-card__price')
picture = soup.find_all('img', class_='product-slider__slide-img swiper-lazy swiper-lazy-loaded')
name = soup.find_all(attrs={"class": "product-card__title"})
price = soup.find_all(attrs={"class": "product-card__price"})
picture = soup.find_all(attrs={"class": "product-slider__slide-img swiper-lazy swiper-lazy-loaded"})
#for prices, names in zip(price, name,):
#print(f" название {names.text} ; цена: {prices.text} ")
for i in range(len(name)):
@@ -42,4 +42,4 @@ for i in range(len(name)):
cursor.close()
connection.close()
connection.close()