Spaces:
Sleeping
Sleeping
File size: 556 Bytes
a746d34 22a4d09 a746d34 22a4d09 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
from django.shortcuts import render
from .models import WebSite
from bs4 import BeautifulSoup
import requests
def index(request):
websites = WebSite.objects.all()
return render(request, 'index.html', {'websites': websites})
def scrape_website(request, pk):
website = WebSite.objects.get(pk=pk)
url = website.url
response = requests.get(url)
soup = BeautifulSoup(response.content, 'html.parser')
data = soup.get_text()
website.data = data
website.save()
return render(request, 'index.html', {'websites': [website]}) |