2017-10-14 21 views
2

我正在尝试从Chromes控制台中查找信息。我正在使用的网站是chrome://Dino。在控制台中,我想要执行和读取的主要命令是Runner().crashed,Runner().horizon.runningTime,Runner().horizon.obstacles和一些其他简单命令。有没有办法使用python从Chrome的控制台执行和读取数据?

我已经尝试过使用硒,但我无法得到它的工作,并谷歌搜索一段时间后,我找不到解决方案。你知道我怎么能做到这一点?

+0

你有机会尝试我的答案吗?我很好奇看到结果! –

回答

0

我能够使用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') 
相关问题