[英]How to properly close phantomjs webpage after use?
I'm trying to read some data from 200+ web pages with PhantomJS and typescript/rxjs What I came up so far is this 我正在尝试使用PhantomJS和typescript / rxjs从200多个网页中读取一些数据,到目前为止,我的想法是
Observable.fromPromise(phantom.createPage()).flatMap(jobPage => {
return Observable.fromPromise(jobPage.open(url)).flatMap(status => {
if (status !== "success") {
console.error("Couldn't load job page for url " + url + " Status: " + status);
jobPage.close();
return Observable.of(undefined)
} else {
return Observable.fromPromise(jobPage.evaluate(function () {
//do some content reading, return data
return data;
}));
}
});
})
And it works, but with every page it gets slower and slower, and finally ends with Memory Exhausted message from Phantom. 它可以正常工作,但是每页都变得越来越慢,最后以来自Phantom的Memory Exhausted消息结束。 I guess it's because I do not close the web pages I'm creating, but I dont have any idea how to do it such case (flatMap creates a new one, I need it for extraction later, and Observable.fromPromise() does not allow me to close the page after I'm done.
我想这是因为我没有关闭正在创建的网页,但是我不知道该怎么做(flatMap创建了一个新的网页,我需要稍后再提取,而Observable.fromPromise()不需要)完成后,请允许我关闭页面。
Any help is appreciated 任何帮助表示赞赏
Ok, figured it out, just need to use 好了,弄清楚了,只需要使用
Observable.fromPromise(phantom.createPage()).flatMap(jobPage => {
//stuff as before
}).finally(function(){
jobPage.close();
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.