[英]How can I read console log (e.g. messages like ok, connected..) of particular website by using a python coding?
I would like to know how to read console log output for a particular website using Python for the automation.我想知道如何使用 Python 为自动化读取特定网站的控制台日志输出。
Currently i am trying to read console data using Selenium, but there is no function that I can use to read my logs, I can read the messages but I cannot read the real time data.目前我正在尝试使用 Selenium 读取控制台数据,但没有可用于读取日志的功能,我可以读取消息但无法读取实时数据。
Is there any other library that can I use?我可以使用任何其他库吗?
One way, how to do it, is to launch Chrome with: chrome.exe" --enable-logging
.一种方法,如何做到这一点,是使用以下命令启动 Chrome:
chrome.exe" --enable-logging
。
Then you can write a function, which would read chrome_debug.log in real time, for example something like this:然后你可以编写一个函数,它会实时读取 chrome_debug.log,例如这样的:
source = open(r'C:\Users\spolm\AppData\Local\Google\Chrome\User Data\chrome_debug.log' , encoding="utf-8")`
export=[]
for line in source:
try:
loadline=line.strip()
x+=1
export.append(loadline)
except UnicodeEncodeError:
line.strip()
x+=1
pass
except UnicodeDecodeError:
line.strip()
x+=1
pass
I hope this helps, if you still looking for the answers after so many years, i can write you full function maybe.我希望这会有所帮助,如果您在这么多年后仍在寻找答案,我也许可以给您写完整的功能。 (Altrough this is not logging internal object, like JSON files in the console...)
(虽然这不是记录内部对象,如控制台中的 JSON 文件......)
so turns out its not that trivial. 因此事实证明它并不那么琐碎。 didn't have the time to try it, but i may have found some options:
没有时间尝试,但是我可能已经找到了一些选择:
option A 选项A
run JS with webdriver: driver.execute_script(script,*args)
使用webdriver运行JS:
driver.execute_script(script,*args)
option B 选项B
chrome devtools API with selenium: 带有硒的chrome devtools API:
hope this will help, good luck ! 希望这会有所帮助,祝你好运!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.