diff --git "a/9.phantomjs/timeout/python\347\250\213\345\272\217\350\207\252\345\212\250\351\207\215\345\220\257.py" "b/9.phantomjs/timeout/python\347\250\213\345\272\217\350\207\252\345\212\250\351\207\215\345\220\257.py" new file mode 100644 index 00000000..1af408c0 --- /dev/null +++ "b/9.phantomjs/timeout/python\347\250\213\345\272\217\350\207\252\345\212\250\351\207\215\345\220\257.py" @@ -0,0 +1,15 @@ +import time +import sys +import os +def restart_program(): + python = sys.executable + os.execl(python, python, * sys.argv) + +if __name__ == "__main__": + print 'start...' +# answer = raw_input("Do you want to restart this program ? ") +# if answer.strip() in "y Y yes Yes YES".split(): +# restart_program() + print u"3秒后,程序将结束...".encode("utf8") + time.sleep(3) + restart_program() diff --git a/9.phantomjs/timeout/timeout_js.js b/9.phantomjs/timeout/timeout_js.js new file mode 100644 index 00000000..fb1aa910 --- /dev/null +++ b/9.phantomjs/timeout/timeout_js.js @@ -0,0 +1,21 @@ +var system = require('system'); +var args = system.args; +var url = args[1]; +var page = require('webpage').create(); +page.settings.resourceTimeout = 5000; // 等待5秒 +page.onResourceTimeout = function(e) { + console.log(e.errorCode); //打印错误码 + console.log(e.errorString); // 打印错误语句 + console.log(e.url); //打印错误url + phantom.exit(1); +}; +page.open(url, function(status) { + if (status === 'success') { + var html = page.evaluate(function() { + return document.documentElement.outerHTML; + }); + console.log(html); + } + phantom.exit(); + }); +//$phantomjs xx.js http://bbs.pcbaby.com.cn/topic-2149414.html