casperJS永远无法完成运行

时间:2018-11-18 00:46:31

标签: phantomjs casperjs headless-browser slimerjs

我在使用casperJS时遇到问题,我想使用casperJS检索视频标签src,但我不能。问题是,当我要加载页面时,即使我禁用了可能加载的所有无用功能,也要花费太多时间(请参见下面的代码)。 重要的是要注意,我不能禁用所有功能,因为视频标签的src属性在开始时就不存在,它是使用javascript“动态”创建的(从数据库中找回它的猜测),所以至少我必须加载此.js文档以创建src属性。

我希望有人能够提供帮助!祝你有美好的一天

编辑:我发现问题出在文档确实具有

编辑2:经过一些研究,我发现有一个php请求可以响应我所寻找的所有内容,我认为我将以这种方式进行探索,如有必要,我会进行一些编辑

var nom;

var casper = require('casper').create({
pageSettings: {
    loadImages:  false,        // do not load images
    loadPlugins: false         // do not load NPAPI plugins (Flash, 
Silverlight, ...)
}
});
casper.options.waitTimeout = 100000;
casper.options.onResourceRequested = function(casper, requestData, request){

var skip = [
'googleads.g.doubleclick.net',
'cm.g.doubleclick.net',
'www.googleadservices.com',
'https://story.snapchat.com/static/css/main.1fa6648e.css',
'https://story.snapchat.com/static/css/base.css',
'https://story.snapchat.com/static/css/vendor.7cd84aaa.css',
'https://snapnet-cdn.storage.googleapis.com/fonts/avenir-next/AvenirNext- 
 Medium.woff2',
'https://snapnet-cdn.storage.googleapis.com/fonts/avenir-next/AvenirNext- 
 DemiBold.woff2',
'https://snapnet-cdn.storage.googleapis.com/fonts/avenir-next/AvenirNext- 
Bold.woff2',
'https://sc-static.net/scevent.min.js',
'https://www.googletagmanager.com/gtag/js?id=UA-41740027-40',
'https://web-frontend-dot-sc- 
analytics.appspot.com/analytics/web/refresh_client',
'https://www.google-analytics.com/analytics.js',
'https://tr.snapchat.com/cm/i?sync_modes=110%2C130',
'https://story.snapchat.com/service-worker.js',
'https://web-frontend-dot-sc-analytics.appspot.com/analytics/web/events',
'https://storysharing.snapchat.com/v1/fetch/coralie.officie? 
 request_origin=ORIGIN_WEB_PLAYER',
'https://search.snapchat.com/upnext?id=coralie.officie&locale=fr-FR',
'https://web-frontend-dot-sc-analytics.appspot.com/analytics/web/events',
'https://web-frontend-dot-sc-analytics.appspot.com/analytics/web/events',
'https://search.snapchat.com/fetchStories',
'https://web-frontend-dot-sc-analytics.appspot.com/analytics/web/events',
 ];

skip.forEach(function(needle) {
if (requestData.url.indexOf(needle) > 0) {
  request.abort();
}
});

}

 function videoo(){
 vid = document.querySelector("video");
 return vid.attributes[0].value;
 }

casper.start("https://story.snapchat.com/s/coralie.officie",function(){
this.waitForSelector("video");
})

casper.then(function(){
nom = this.evaluate(videoo);
this.echo(nom);
});

casper.run();

0 个答案:

没有答案