我是刮痧的初学者。我已经抓取了一些数据。这里有两个问题:所有数据都填充到一行中,每次刷新页面时,每次都将数据保存到数据库中。
import requests
from django.shortcuts import render, redirect
from bs4 import BeautifulSoup
from .models import Content
toi_r = requests.get("some web site")
toi_soup = BeautifulSoup(toi_r.content, 'html5lib')
toi_headings = toi_soup.findAll("h2", {"class": "entry-title format-icon"})[0:9]
toi_category = toi_soup.findAll("a", {"class": ""})[0:9]
toi_news = []
toi_cat =[]
for th in toi_headings:
toi_news.append(th.text)
for tr in toi_category:
toi_cat.append(tr.text)
#saving the files in database
n = Content()
n.title = toi_news
n.category = toi_cat
n.save()