Как я могу просмотреть данные моего бота python в таблице mysql?
В папке bookfiles есть боты, которые я написал с помощью python. Я импортировал свой класс модели внутрь ботов. Я создал таблицу в файле models.py в базе данных, но данные ботов не отображаются. Есть только названия столбцов. Как я могу отобразить эти данные в таблице моей базы данных?
Ниже я привел код бота.
from ast import Str
from base64 import decode
import requests
from bs4 import BeautifulSoup
import pandas as pd
import csv
from time import sleep
from random import randint
import numpy as np
from bookList.models import BookList
headers = dict()
headers[
"User-Agent"
] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36"
def sendBooksToMysql():
bkmArt()
def bkmArt():
pages = range(1, 3, 1)
for page in pages:
url = "https://www.bkmkitap.com/sanat"
results = requests.get(url, headers=headers)
soup = BeautifulSoup(results.content, "html.parser")
book_div = soup.find_all("div", class_="col col-12 drop-down hover lightBg")
sleep(randint(2, 10))
for bookSection in book_div:
img_url = bookSection.find("img", class_="lazy stImage").get('data-src')
name = bookSection.find("a",class_="fl col-12 text-description detailLink").get('title')
author = bookSection.find("a", class_="fl col-12 text-title").get('title').replace('Model:', '')
publisher = bookSection.find("a", class_="col col-12 text-title mt").get('title').replace(name, '')
price = bookSection.find("div", class_="col col-12 currentPrice").text.replace('\n', '').replace('TL', ' TL')
b_link = bookSection.find("a").get('href')
bookList = BookList.objects.using("bookList").update_or_create(
site_name="Bkmkitap",
site_id="1",
image=img_url,
#book=name,
#author=author,
publisher=publisher,
price=price,
link=b_link,
category_name="Sanat",
category_id="1",
defaults={
"site_name":"Bkmkitap",
"site_id":"1",
"image":img_url,
"book":name,
"author":author,
"publisher":publisher,
"price":price,
"link":b_link,
"category_name":"Sanat",
"category_id":"1",
}
)
Ниже приведено содержимое моего файла models.py.
from django.db import models
# Create your models here.
class BookList(models.Model):
site_name = models.TextField()
site_id = models.TextField()
image = models.TextField()
book = models.TextField()
author = models.TextField()
publisher = models.TextField()
price = models.TextField()
link = models.TextField()
category_name = models.TextField()
category_id = models.TextField()
class Meta:
managed = True
db_table = 'books'