H
H
hsuper2019-01-11 14:36:36
Django
hsuper, 2019-01-11 14:36:36

Error adding to db?

The code should parse and add books to db

from requests import get
from bs4 import BeautifulSoup
from books.models import Book


for book_id in range(101724, 130000):
    try: 
        html = get('http://read.ru/book/{0}/'.format(book_id))
        b = BeautifulSoup(html.text, "html.parser")
        book_article = b.select('.book-article--title')[0].getText()
        book_description = b.select('.book-article--description p')[0].getText()
        text = "Book title: {0} Description: {1}".format(book_article, book_description)

        Book.objects.create(title=book_article, slug=slugify(book_article), description=book_description)
        print(text)
    except:
        print("Error")

I get an error: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
How to fix?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question