mercredi 18 septembre 2019

Why the web page is not refreshing my value , when i use Beautifulsoup?

Hello everyone , I am simply trying to get any facebook page like count , and to show it in simple web-page , and i used Beautifulsoup to scrup the like count , but the problem once the script is running , the value are not being refreshed , is there any way to re-run the script every margin of time ?

Here is my code 


    /////////////////////////////////////////////////
this is the .py script


      from flask import Flask, render_template

        import requests
        import string
        import lxml.html
        import lxml.html.clean
        import unicodedata
        from bs4 import BeautifulSoup
        import re


        user = 'EttounsiyaTV'
        url = 'https://www.facebook.com/'+ user
        response = requests.get(url)
        soup = BeautifulSoup(response.content,'lxml')
        fe = soup.find('div', attrs={'class': '_4-u3 _5sqi _5sqk'})
        f = fe.text
        nonBreakSpace = u'\xa0'
        soup = f.replace(nonBreakSpace, '')

        soup = re.sub("\D","",soup)

        fan_number = int(soup)
        old_number = 6206360
        difference = old_number - fan_number


        print("lost in one day {difference} ".format(difference=difference))

        print(fan_number)


        app = Flask(__name__)



        @app.route("/")
        def home():
            return render_template("index.html",text=soup,text2=f)


        if __name__ == "__main__":
            app.run(debug=True)

///////////////////////////
and here is the html which is found in templates and working fine but static

    <!DOCTYPE html>
    <html lang="en" dir="ltr">
    <meta http-equiv="refresh" content="5"/>

      <head>
           <title>Flask app</title>
        <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">


      </head>
      <body>
       <center> <h1> </h1> <center>

      </body>
    </html>

How to upload it on free host , and make it refresh every 5 seconds or something ?




Aucun commentaire:

Enregistrer un commentaire