I am trying to monitor a page for any updates. However, I need to keep the same session and cookies so I can't just send a whole new request.
How can I check for updates in the HTML within my current request? The page won't just be updated, I will be redirected but the URL remains the same.
Here is my current code:
import requests
url = 'xxx'
headers = {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1)
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'
}
response = requests.get(url, headers=headers, allow_redirects=True, config={'keep_alive': True})
def get_status():
html = response.text # this should be the current HTML, not the HTML when I made the initial request
if x in html:
status = "exists"
else:
status = "null"
return status
print(get_status())
EDIT: I will be using a while loop to run this function every 5 seconds to check if the status is = "exists".
EDIT2: I tried to implement it via requests_html but I am not getting as many cookies as I should be:
import requests_html
from requests_html import HTMLSession
session = HTMLSession()
session.headers.update({'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36'})
r = session.get('x')
r.html.render(reload=False)
print(r.cookies.get_dict())