【问题标题】:How can I read console log (e.g. messages like ok, connected..) of particular website by using a python coding?如何使用 python 编码读取特定网站的控制台日志(例如,ok、connected 等消息)?
【发布时间】:2019-07-11 16:49:40
【问题描述】:

我想知道如何使用 Python 读取特定网站的控制台日志输出以实现自动化。

目前我正在尝试使用 Selenium 读取控制台数据,但没有可用于读取日志的功能,我可以读取消息但无法读取实时数据。

还有其他可以使用的库吗?

【问题讨论】:

标签: javascript python python-2.7 api selenium


【解决方案1】:

一种方法是通过以下方式启动 Chrome:chrome.exe" --enable-logging

然后你可以写一个函数,它会实时读取 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

【讨论】:

    【解决方案2】:

    事实证明,这并不是那么微不足道。没有时间尝试,但可能找到了一些选择:

    选项 A

    1. Get console content with JS

    2. Run JS with webdriver: driver.execute_script(script,*args)

    3. Get value back to python from selenium

    选项 B

    带有 Selenium 的 Chrome 开发工具 API:

    Selenium side

    DevTools side

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-07-29
      • 1970-01-01
      • 2016-09-06
      • 2021-04-10
      • 1970-01-01
      • 2016-02-14
      • 1970-01-01
      相关资源
      最近更新 更多