mirror of
https://github.com/KUlishevgeniy/c22712.git
synced 2026-09-23 23:50:21 +00:00
Update parcing.py
This commit is contained in:
@@ -1,35 +1,16 @@
|
|||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
from selenium.webdriver import Chrome
|
||||||
from selenium import webdriver
|
from selenium import webdriver
|
||||||
from selenium.webdriver.chrome.service import Service
|
from selenium.webdriver.chrome.service import Service
|
||||||
import psycopg2
|
import time
|
||||||
import wget
|
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')
|
||||||
|
|
||||||
browser = webdriver.Chrome(service=Service('C:\\Users\\Yekaterina\\Downloads\\chromedriver_win32.zip\\chromedriver.exe'))
|
|
||||||
browser.get('https://msk.sushi-market.com/menu/rolly')
|
|
||||||
soup = BeautifulSoup(browser.page_source, "lxml")
|
|
||||||
|
|
||||||
Name = soup.find_all(attrs={"class": "goodsBlockName device-show"})
|
name=soup.find_all('div', class_='app-catalog-1tp0ino e1an64qs0')
|
||||||
Info = soup.find_all(attrs={"class": "goodsBlockWeight"})
|
print (name[1].text)
|
||||||
Des = soup.find_all(attrs={"class": "cardsList_text"})
|
description=soup.find_all('div', class_='app-catalog-1o4umte eevw8x70')
|
||||||
Price = soup.find_all(attrs={"class": "goodsBlockPrice"})
|
print (description[1].text)
|
||||||
Image = soup.find_all(attrs={"class": "cardsList_img add-to-cart__img"})
|
|
||||||
|
|
||||||
connection = psycopg2.connect(host='localhost', dbname='dbdata', user='postgres', password='Q1w2e3r4')
|
|
||||||
cursor = connection.cursor()
|
|
||||||
create_q = '''CREATE TABLE Food (ID serial primary key, Name varchar(5000), Info varchar(5000), Des varchar(10000), Price varchar(6000), src varchar(1000))'''
|
|
||||||
cursor.execute(create_q)
|
|
||||||
connection.commit()
|
|
||||||
|
|
||||||
for j in range(25):
|
|
||||||
url = Image[j].find('img').attrs['src']
|
|
||||||
tempf = f"img\\food{j}.jpg"
|
|
||||||
wget.download(url, tempf)
|
|
||||||
insert_query = f'''INSERT into public.Food(Name, Info, Des, Price, src) values ('{Name[j].text}','{Info[j].text}','{Des[j].text}', '{Price[j].text}', '{tempf}') '''
|
|
||||||
cursor.execute(insert_query)
|
|
||||||
connection.commit()
|
|
||||||
|
|
||||||
cursor.execute("SELECT * from Food")
|
|
||||||
print(cursor.fetchall())
|
|
||||||
|
|
||||||
cursor.close()
|
|
||||||
connection.close()
|
|
||||||
|
|||||||
Reference in New Issue
Block a user