我能够使用Selenium(使用C#)获取所有列出的信息。 'How to output result of Javascript execution to console?'给了我一个提示。
// 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}");
每个人都应该能够使用driver.execute_script在Python做同样的。
crashed = driver.execute_script('return Runner().crashed')
runningTime = driver.execute_script('return Runner().horizon.runningTime')
obstcles = driver.execute_script('return Runner().horizon.obstacles')
你有机会尝试我的答案吗?我很好奇看到结果! –