Answer the question
In order to leave comments, you need to log in
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")
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question