From ab0d9a07b1ebb59f8a977cb2f7d8ec7a53ffbeda Mon Sep 17 00:00:00 2001 From: luyishisi <543429245@qq.com> Date: Sun, 12 Feb 2017 23:08:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=B6=85=E6=97=B6=E6=96=B9?= =?UTF-8?q?=E9=9D=A2=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...52\345\212\250\351\207\215\345\220\257.py" | 15 +++++++++++++ 9.phantomjs/timeout/timeout_js.js | 21 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 "9.phantomjs/timeout/python\347\250\213\345\272\217\350\207\252\345\212\250\351\207\215\345\220\257.py" create mode 100644 9.phantomjs/timeout/timeout_js.js 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