每次网页上的文本更新时抓取网站并返回值
我正在尝试编写一个程序来监视一个网站,该网站的文本变化非常快,至少每秒一次。我想要一个变量,每次网页上的文本更新时都会更新。网站上有多个快速更新的文本,我可能会扩展我的代码以跟踪所有文本,但现在我只专注于跟踪其中一个。
我目前已经尝试使用 javascript,但如果存在一种方法可以用不同的语言(例如 python)执行此操作,我将切换到该语言。在 javascript 中,我尝试使用 Selenium 库将代码注入网站,并使用 MutationObserver
,每次我监视的文本发生变化时都会更新变量。我遇到的问题是我的程序无法访问该变量,因为它存在于网站范围内。我也尝试过使用 Nightmare 库,但遇到了同样的问题。我可以返回变量,但我只会收到该变量当时的状态,它不会更新。
无论如何,是否可以将代码注入到可以运行回调函数的网站中,从而为我的程序提供值?或者让注入的代码返回一个对象,该对象将在站点文本更新时不断更新?或者,如果我应该采取完全不同的方式来做到这一点,请告诉我。谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论