mirror of
https://github.com/KUlishevgeniy/c22712.git
synced 2026-09-23 23:50:21 +00:00
Телеграм Бот
This commit is contained in:
@@ -4,6 +4,7 @@ from bs4 import BeautifulSoup
|
||||
from selenium import webdriver
|
||||
from selenium.webdriver.chrome.service import Service
|
||||
import time
|
||||
|
||||
i = 1
|
||||
s = Service("С:\DATA\ChromeDriver\chromedriver.exe")
|
||||
browser = webdriver.Chrome(service=s)
|
||||
@@ -24,12 +25,12 @@ features = soup.find_all('span', class_="product-feature-list__value")
|
||||
pictures = soup.find_all('div', class_="product-picture-container")
|
||||
connection=psycopg2.connect(host='localhost', dbname='dbdata', user='postgres', password='Q1w2e3r4')
|
||||
cursor = connection.cursor()
|
||||
""" insert = CREATE TABLE public.laptops(
|
||||
insert = """CREATE TABLE public.laptops(
|
||||
id serial primary key,
|
||||
product varchar(100),
|
||||
price varchar(15),
|
||||
diagonal varchar(5),
|
||||
resolution varchar(20),
|
||||
Product varchar(100),
|
||||
Price varchar(15),
|
||||
Diagonal varchar(5),
|
||||
Resolution varchar(20),
|
||||
CPU varchar(50),
|
||||
RAM varchar(15),
|
||||
Graphics_Controller varchar(40),
|
||||
@@ -37,7 +38,7 @@ Volume varchar(25),
|
||||
src varchar(100)
|
||||
);
|
||||
"""
|
||||
insert = """TRUNCATE TABLE public.laptops; ALTER SEQUENCE laptops_id_seq RESTART WITH 1;"""
|
||||
|
||||
cursor.execute(insert)
|
||||
connection.commit()
|
||||
for i in range(len(productst)):
|
||||
@@ -49,13 +50,11 @@ for i in range(len(productst)):
|
||||
wget.download(url, filename)
|
||||
t = pricest[i].text.replace("\xa0", " ")
|
||||
insert = f"""INSERT INTO public.laptops(
|
||||
product, price, diagonal, resolution, CPU, RAM, Graphics_Controller, Volume, src)
|
||||
Product, Price, Diagonal, Resolution, CPU, RAM, Graphics_Controller, Volume, src)
|
||||
VALUES
|
||||
('{productst[i].text.strip()}', '{t.strip()}', '{u[0][:u[0].find("/")]}', '{u[0][u[0].find("/")+1:]}',
|
||||
'{u[2]}', '{u[4]+" "+u[5]}', '{u[6]}', '{u[8]}', '{filename}');"""
|
||||
cursor.execute(insert)
|
||||
connection.commit()
|
||||
cursor.execute("select * from laptops")
|
||||
print("Результат", cursor.fetchall())
|
||||
cursor.close()
|
||||
connection.close()
|
||||
connection.close()
|
||||
Reference in New Issue
Block a user