简体   繁体   中英

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.

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.

Is there any other library that can I use?

One way, how to do it, is to launch Chrome with: chrome.exe" --enable-logging .

Then you can write a function, which would read chrome_debug.log in real time, for example something like this:

   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...)

so turns out its not that trivial. didn't have the time to try it, but i may have found some options:

option 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

option B

chrome devtools API with selenium:

selenium side

DevTools side

hope this will help, good luck !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM