import codecs
import json
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
capabilities = DesiredCapabilities.CHROME
capabilities['loggingPrefs'] = { 'browser':'ALL' }
options = webdriver.ChromeOptions()
driver = webdriver.Chrome(desired_capabilities=capabilities, chrome_options=options)
driver.get('http://foo.com')
# print console log messages
info=[]
for entry in driver.get_log('browser'):
if entry['level']=='SEVERE':
info.append(entry)
j = json.dumps(info, indent=4,ensure_ascii=False)
with codecs.open('info.json', "w", "utf-8") as f:
f.write(j)
driver.close()