I am doing web scraping and I want to store the information in the database. I have the connection with the database in the 'settings' file like this:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'dbname',
'USER': 'root',
'PASSWORD': 'password',
'HOST': 'localhost',
'PORT': 'port'
}
}
The web scraping I have it in another file like this:
from bs4 import BeautifulSoup
import requests
url = "https://www.somepage.com"
result = requests.get(url)
soup = BeautifulSoup(result.text, "html.parser")
find_by_class = soup.find('div', attrs={"class":"body"}).find_all('p')
I want to store what is in find_by_class in the database.
Also I have created the models.
from django.db import models
class SomeModel(models.Model):
description = models.TextField(max_length=1000)
from models import SomeModelin the scraping file and then tried thisdescription = find_by_class. But of course it didn't work.