Forums

I have to reload the App to get data in web scraping. It should done without reloading the App.

import bs4 import requests

def corona(request):
    def getCoronaReport(url):
        r = requests.get(url)
        r.raise_for_status()
        report = []
        soup = bs4.BeautifulSoup(r.text, 'html.parser')
        elem = soup.select('#maincounter-wrap > div > span ')
        report = [elem[0].text,elem[1].text,elem[2].text]

        return report
    report = getCoronaReport('https://www.worldometers.info/coronavirus/country/india/')
    S = report[0][:1] + report[0][1 + 1:]
    print('Total Cases in India:\nCases:-'+S+'\nDeaths:-'+report[1]+'\nRecovry:-'+report[2])
    total = int(S)
    active = int(S)-int(report[1])-int(report[2])
    death = int(report[1])
    recovry = int(report[2])
    context = {'total':total,'active':active,'death':death,'recovry':recovry}
    return render(request,'homepage/corona.html',context)

Everytime have to reload to get new values. In webscrapping

Looks like you should separate your web scrapping from displaying data in your web app. You can do web scrapping in a Scheduled Task or Always-on Task (see "Tasks" page on PythonAnywhere) and store data in the database.