我正在尝试找到一种从Chrome控制台读取信息的方法。我正在使用的网站是chrome://Dino
。在控制台中,我想执行和读取的主要命令是Runner().crashed
,Runner().horizon.runningTime
,Runner().horizon.obstacles
,和其他一些简单的命令。
我曾经尝试过使用Selenium,但是我无法使其正常工作,并且在搜索了一段时间之后,我找不到解决方案。你知道我怎么能做到吗?
我能够使用Selenium(与C#)来获取所有列出的信息。“如何将Javascript执行结果输出到控制台?” 给了我一个提示。
// initialize the ChromeDriver, and get the jsExecutor
// This step may be different for Python
var chromeDriver = new ChromeDriver();
var jSExecutor = (IJavaScriptExecutor)chromeDriver;
// navigate to the page
chromeDriver.Navigate().GoToUrl("chrome://dino");
// get the values, using js command
var crashed = jSExecutor.ExecuteScript("return Runner().crashed");
var runningTime = jSExecutor.ExecuteScript("return Runner().horizon.runningTime");
var obstcles = jSExecutor.ExecuteScript("return Runner().horizon.obstacles");
// print the values
Console.WriteLine($"{crashed}, {runningTime}, {obstcles}");
人们应该能够在Python中使用driver.execute_script来执行相同的操作。
crashed = driver.execute_script('return Runner().crashed')
runningTime = driver.execute_script('return Runner().horizon.runningTime')
obstcles = driver.execute_script('return Runner().horizon.obstacles')
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句