Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class DataBase:
- def __init__(self, user, password, db):
- self.user = user
- self.password = password
- self.db = db
- try:
- conn = self.get_conn()
- # if conn.is_connected():
- # print('Подключение прошло успешно.')
- except Error as e:
- print(e)
- def get_conn(self):
- conn = mysql.connector.connect(user=self.user,
- password=self.password,
- db=self.db)
- return conn
- def get_subcategory_id(self, title):
- sql = "SELECT id FROM buy.subcategory WHERE title = '{0}';".format(title)
- conn = self.get_conn()
- c = conn.cursor()
- c.execute(sql)
- id = c.fetchall()
- return (id)
- class Tesco:
- def write_database(self, data):
- data_base = db.DataBase('root', '123456', 'buy')
- data_base.get_subcategory_id(data['title'])
- def get_products(self, html):
- soup = BeautifulSoup(html, 'lxml')
- name_sub_category = soup.find('span', class_='plp--breadcrumbs--last-crumb').text
- data = {
- 'title': name_sub_category
- }
- print(self.write_database(data))
- def write_database(self, data):
- data_base = db.DataBase('root', '123456', 'buy')
- return data_base.get_subcategory_id(data['title'])
- cursor.execute(sql, ())
- for field in cursor:
- print("found: ", fields)
Add Comment
Please, Sign In to add comment