From d41f65a1dfb8e671feedf2718f3536b1752929d1 Mon Sep 17 00:00:00 2001 From: TatianaFilcheva <124861990+TatianaFilcheva@users.noreply.github.com> Date: Wed, 5 Apr 2023 09:43:52 +0300 Subject: [PATCH 1/6] Add files via upload --- fars.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 fars.py diff --git a/fars.py b/fars.py new file mode 100644 index 0000000..7740187 --- /dev/null +++ b/fars.py @@ -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() \ No newline at end of file From 770b4affae4a5a05be37a8b46f88e0131fb4fb48 Mon Sep 17 00:00:00 2001 From: TatianaFilcheva <124861990+TatianaFilcheva@users.noreply.github.com> Date: Wed, 5 Apr 2023 09:56:40 +0300 Subject: [PATCH 2/6] Add files via upload --- Задания/task1/Filcheva/fars.py | 44 ++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Задания/task1/Filcheva/fars.py diff --git a/Задания/task1/Filcheva/fars.py b/Задания/task1/Filcheva/fars.py new file mode 100644 index 0000000..7740187 --- /dev/null +++ b/Задания/task1/Filcheva/fars.py @@ -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() \ No newline at end of file From 614d34b6a6366fa6774933eea63c0557b90ee65e Mon Sep 17 00:00:00 2001 From: TatianaFilcheva <124861990+TatianaFilcheva@users.noreply.github.com> Date: Wed, 5 Apr 2023 09:57:57 +0300 Subject: [PATCH 3/6] Rename fars.py to bd.py --- Задания/task1/Filcheva/{fars.py => bd.py} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename Задания/task1/Filcheva/{fars.py => bd.py} (96%) diff --git a/Задания/task1/Filcheva/fars.py b/Задания/task1/Filcheva/bd.py similarity index 96% rename from Задания/task1/Filcheva/fars.py rename to Задания/task1/Filcheva/bd.py index 7740187..edf9e9c 100644 --- a/Задания/task1/Filcheva/fars.py +++ b/Задания/task1/Filcheva/bd.py @@ -41,4 +41,4 @@ for j in range(10): cursor.execute('select * from Distilleries') print(cursor.fetchall()) cursor.close() -connection.close() \ No newline at end of file +connection.close() From a0f90f68488d602c08f26569377d03247c02e4c7 Mon Sep 17 00:00:00 2001 From: 13danny13 Date: Wed, 5 Apr 2023 11:48:31 +0300 Subject: [PATCH 4/6] database --- Задания/task1/Kuznetsov/db.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Задания/task1/Kuznetsov/db.py b/Задания/task1/Kuznetsov/db.py index 28c1c54..9764137 100644 --- a/Задания/task1/Kuznetsov/db.py +++ b/Задания/task1/Kuznetsov/db.py @@ -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() \ No newline at end of file From 959ba6d3a68d45e6c4772234ece78590e148f330 Mon Sep 17 00:00:00 2001 From: Axeten Date: Wed, 5 Apr 2023 22:23:02 +0300 Subject: [PATCH 5/6] parsing hellride and input data in database --- Задания/task1/romanov/bdpars.py | 45 +++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Задания/task1/romanov/bdpars.py diff --git a/Задания/task1/romanov/bdpars.py b/Задания/task1/romanov/bdpars.py new file mode 100644 index 0000000..41bc067 --- /dev/null +++ b/Задания/task1/romanov/bdpars.py @@ -0,0 +1,45 @@ +import wget +import psycopg2 +from bs4 import BeautifulSoup +from selenium import webdriver +from selenium.webdriver.chrome.service import Service +connection = psycopg2.connect(host='localhost', dbname='postgres', + user='postgres', password='Q1w2e3r4') + +cursor = connection.cursor() + +cr_qwery = """ create table parser + (id serial primary key, + name varchar(60), + price varchar(15), + picture varchar(100))""" + +cursor.execute(cr_qwery) +connection.commit() + +s = Service('C:\Desktop\exe\chromedriver.exe') +browser = webdriver.Chrome(service=s) +browser.get('https://www.hellride.ru/catalog/zapchasti-dlya-tryukovyh-samokatov/deki') +html_code = browser.page_source +soup = BeautifulSoup(html_code, 'lxml') + +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)): + url = picture[i].attrs['src'] + filename = f"C:\\Users\\Михаил\PycharmProjects\pythonProject8\\venv\Pictures\{i}.jpg" + wget.download(url, filename) + ins_qwery = f"""insert into public.Parser(name, price, picture) + values ('{name[i].text}', '{price[i].text}', '{filename}')""" + cursor.execute(ins_qwery) + connection.commit() + + + + +cursor.close() + +connection.close() \ No newline at end of file From 48465c6ab0e222d726d7953a50cde8f500704d9d Mon Sep 17 00:00:00 2001 From: Axeten Date: Wed, 5 Apr 2023 22:24:46 +0300 Subject: [PATCH 6/6] parsing hellride and input data in database --- Задания/task1/romanov/bd | 45 ---------------------------------------- 1 file changed, 45 deletions(-) delete mode 100644 Задания/task1/romanov/bd diff --git a/Задания/task1/romanov/bd b/Задания/task1/romanov/bd deleted file mode 100644 index 7f5d9c1..0000000 --- a/Задания/task1/romanov/bd +++ /dev/null @@ -1,45 +0,0 @@ -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='postgres', - user='postgres', password='Q1w2e3r4') - -cursor = connection.cursor() - -cr_qwery = """ create table parser - (id serial primary key, - name varchar(60), - price varchar(15), - picture varchar(100))""" - -cursor.execute(cr_qwery) -connection.commit() - -s = Service('C:\Desktop\exe\chromedriver.exe') -browser = webdriver.Chrome(service=s) -browser.get('https://www.hellride.ru/catalog/zapchasti-dlya-tryukovyh-samokatov/deki') -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') -#for prices, names in zip(price, name,): - #print(f" название {names.text} ; цена: {prices.text} ") -for i in range(len(name)): - url = picture[i].attrs['src'] - filename = f"C:\\Users\\Михаил\PycharmProjects\pythonProject8\\venv\Pictures\{i}.jpg" - wget.download(url, filename) - ins_qwery = f"""insert into public.Parser(name, price, picture) - values ('{name[i].text}', '{price[i].text}', '{filename}')""" - cursor.execute(ins_qwery) - connection.commit() - - - - -cursor.close() - -connection.close()