使用python检测javascript控制台输出 [英] Detect javascript console output with python
问题描述
当我在一个javascript繁重的应用程序中工作时,我喜欢使用Console.log()进行调试。但是,我想确保我已正确压缩生产中的所有控制台日志记录。
When I'm working in a javascript-heavy application I like to use Console.log() a lot for debugging. However, I want to ensure I've properly suppressed all console logging in production.
我想创建一个python脚本来遍历网站并生成一个列表向控制台写入内容的页面。我知道我可以在最小化之前翻录javascript文件并搜索Console.Log,但我经常是项目的分析师,因此无法访问代码库。我们还有很多网站一段时间没有被触及,但可以使用扫描(伟大的实习项目:-))。
I'd like to create a python script to walk through a site and generate a list of pages that write something to the console. I know I could just have it rip through the javascript files before minimization and search for "Console.Log" but I'm often the analyst on a project and consequently don't have access to the codebase. We also have a ton of sites that haven't been touched in a while but could use a scan (great intern project :-) ).
这是否适用于python ?
Is this doable with python?
推荐答案
你可以做的是使用 selenium
浏览器自动化工具并检查控制台日志:
What you can do is to use selenium
browser automation tool and check the console logs:
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
capabilities = DesiredCapabilities.CHROME
capabilities['loggingPrefs'] = { 'browser':'ALL' }
driver = webdriver.Chrome(desired_capabilities=capabilities)
driver.get('http://foo.com')
# print console log messages
for entry in driver.get_log('browser'):
print entry
取自使用Selenium Python API绑定从Chrome获取console.log输出。
这篇关于使用python检测javascript控制台输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!