爬虫爬网页时,有时页面一直在加载中,其网页加载状态document.readyState
分为:
uninitialized
:(Uninitialized) the send( ) method has not yet been invoked. (未初始化)还没有调用send()方法;loading
:the send( ) method has been invoked, request in progress. (载入)已调用send()方法,正在发送请求;loaded
:the send( ) method has completed, entire response received. (载入完成)send()方法执行完成,已经接收到全部响应内容;interactive
:the response is being parsed. (交互)正在解析响应内容;completed
:the response has been parsed, is ready for harvesting. (完成)响应内容解析完成,可以在客户端调用了;
如果要停止加载,则可以执行js脚本:window.stop()
;
//当页面一直在加载中(比如引用某个图片或脚本未完成),但所需内容已显示出来
if (document.readyState == 'interactive')
{
window.stop()`
}
参考资料 js 判断页面加载状态