Python: check a content on a specific webpage update

 

import requests
from bs4 import BeautifulSoup
import time
from datetime import datetime


current_value="Current Value on the webpage"
t_frequency = 60 //set time intervals in seconds for repeat running the program
web_url="https://example.com"
headers = {"Accept-Language":"replace", "User-agent":"replace"} //go to http://myhttpheader.com/
control_value = current_value
t=
0
while control_value == current_value: //run the following code if the value is not changed
response = requests.get(
url=web_url, headers=headers).text
soup = BeautifulSoup(response
, "html.parser")
status = soup.find_all(
"p", {"class": "class names"}) //locate the html elements
control_value = status[0].text //get the text in that html tag
now = datetime.now()
t=t+
1 // count how many times the code has been run
current_time = now.strftime("%H:%M:%S")
print("Tried " + str(t) + " times. " + current_time + ": " + value) // return the result
time.sleep(t_frequency)

skfjsa

0 Comments