简体   繁体   English

如何使用 python 编码读取特定网站的控制台日志(例如,ok、connected 之类的消息)?

[英]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

  1. get console content with JS 使用JS获取控制台内容

  2. run JS with webdriver: driver.execute_script(script,*args) 使用webdriver运行JS: driver.execute_script(script,*args)

  3. get value back to python from selenium 从硒中获取价值回到python

option B 选项B

chrome devtools API with selenium: 带有硒的chrome devtools API:

selenium side 硒侧

DevTools side DevTools方面

hope this will help, good luck ! 希望这会有所帮助,祝你好运!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在PHP中使用Ajax从网站(例如IMDB)中获取数据 - How can I fetch data from a website (e.g. IMDB ) using Ajax in PHP 如何生成特定颜色的随机阴影列表? (例如橙色的随机阴影) - How can I generate a list of random shades of a particular color? (e.g. random shade of orange) 我如何以编程方式查看网站发出的请求(例如 API 或资源请求) - How can I programmatically see what requests (e.g. API or resource requests) are being made by a website Javascript函数就像对象,即“$”可以用作函数,例如$()以及对象$ - Javascript Function like Objects i.e. “$” can be used as a function e.g. $() as well as an object $ 如何使用 JavaScript 验证图像尺寸(表示为“5X4”)? - How can I validate image sizes (expressed as e.g. “5X4”) using JavaScript? 如何检查浏览器是否缓存了特定资源(例如图像)? - How to check if a particular resource (e.g. image) is cached by the browser? 如何更改网站上的滚动行为(例如速度、加速度)? - How to change scroll behavior (e.g. speed, acceleration) on website? Unicode:如何获取诸如 ã 之类的字符的所有代码点(以便它可以在 JavaScript 正则表达式中使用)? - Unicode: How to obtain all code points for a character like e.g. ã (so it can be used in JavaScript regex)? 比较简单的日期字符串(例如console.log(“ 24.3.2018” &lt;“ 20.3.2017”)) - Comparing simple date strings (e.g. console.log(“24.3.2018” < “20.3.2017”)) 我可以对JavaScript设置时间限制(例如,使用iframe)吗? - Can I put impose a time limit on JavaScript (e.g., using an iframe)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM