[英]How to run JavaScript function in browser console?
In my Python program, I need to run the hcaptchaCallback function (screenshot), but the function name has a different numbers each time.在我的 Python 程序中,我需要运行 hcaptchaCallback function(截图),但 function 名称每次都有不同的数字。 Can I somehow run this function by specifying only the first part of the name (hcaptchaCallback)?我可以通过仅指定名称的第一部分 (hcaptchaCallback) 以某种方式运行此 function 吗?
driver.execute_script('hcaptchaCallback...()')
There is nothing that lets you really do that.没有什么能让你真正做到这一点。 You might be able to pull off looping over the globals and looking for a variable that starts with your string.您可能能够结束对全局变量的循环并查找以您的字符串开头的变量。
window[Object.keys(window).find(k=>k.startsWith("hcaptchaCallback"))]();
that will call it the way you showed, but looking at the function signature, looks like you are going to have to use call()这将按照您显示的方式调用它,但查看 function 签名,看起来您将不得不使用call()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.