【发布时间】:2015-05-31 22:32:31
【问题描述】:
是否可以解析有一些 js 错误(例如“$ 未定义”)的外部页面 http://example.com,捕获这些错误并通过 console.log() 打印它们?
【问题讨论】:
标签: javascript node.js parsing cheerio
是否可以解析有一些 js 错误(例如“$ 未定义”)的外部页面 http://example.com,捕获这些错误并通过 console.log() 打印它们?
【问题讨论】:
标签: javascript node.js parsing cheerio
是的,这是可能的。基本上你需要下载一个页面并在无头浏览器中呈现它,例如PhantomJS。
已经有人这样做了:http://npmjs.com/package/phantom-check
$ phantom-check http://example.com
Phantom is checking http://example.com
[info] [phantom] Starting...
[info] [phantom] Running suite: 2 steps
[debug] [phantom] opening url: http://example.com/, HTTP GET
[debug] [phantom] Navigation requested: url=http://example.com/, type=Other, willNavigate=true, isMainFrame=true
[debug] [phantom] url changed to "http://example.com/"
[debug] [phantom] Successfully injected Casper client-side utilities
Page http://example.com has no errors
【讨论】: