Skip to content

Commit

Permalink
新增超时方面代码
Browse files Browse the repository at this point in the history
  • Loading branch information
luyishisi committed Feb 12, 2017
1 parent 8049345 commit ab0d9a0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
15 changes: 15 additions & 0 deletions 9.phantomjs/timeout/python程序自动重启.py
Original file line number Diff line number Diff line change
@@ -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()
21 changes: 21 additions & 0 deletions 9.phantomjs/timeout/timeout_js.js
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ab0d9a0

Please sign in to comment.