So this is how you do it with Python:
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
# enable browser logging
d = DesiredCapabilities.CHROME
d['loggingPrefs'] = { 'browser':'ALL' }
driver = webdriver.Chrome(desired_capabilities=d)
# load some site
driver.get('https://www.edureka.co/')
# print messages
for entry in driver.get_log('browser'):
print entry
Those entries whose source field equal to 'console-api' correspond to the console messages, & the message itself is stored in message field. For further understanding, you can refer to the Selenium Course.