I'm trying to write a program that monitors a website that has text that changes very quickly, at least once per second. I want to have a variable that updates every time the text on the webpage updates. There are multiple pieces of text on the website that update quickly, I will likely expand my code to keep track of all of it, but right now I am focussing on just tracking one.
I have currently tried using javascript, but if there exists a way to do this in a different language, such as python, I will switch over to that. In javascript, I have tried using the Selenium library to inject code into the website and using a MutationObserver which updates a variable every time the text I am monitoring changes. The problem I am having is that my program does not have access to this variable as it exists within the scope of the website. I have also tried using the Nightmare library but run into the same problem. I can return the variable, but I will only receive whatever the state of the variable was at that moment in time, it will not update.
Is there anyway to inject code into the website that can run a callback function that gives the value to my program? Or have the injected code return an object which will constantly get updated when the site's text updates? Or if there is an entirely different way I should go about doing this, please let me know. Thank you.