Skip to content

Instantly share code, notes, and snippets.

@lgh06
Last active March 28, 2017 11:21
Show Gist options
  • Save lgh06/ec1b71ffaabaf9d4baa500f8236a9724 to your computer and use it in GitHub Desktop.
Save lgh06/ec1b71ffaabaf9d4baa500f8236a9724 to your computer and use it in GitHub Desktop.
using phantom package.
var phantom = require('phantom');
var phInstance = null;
phantom.create(['--ignore-ssl-errors=yes', '--load-images=no']).then(instance => {
phInstance = instance;
return instance.createPage();
}).then(page => {
// use page
page.on('onResourceRequested', function (requestData){
console.info('Requesting', requestData.url)
});
page.open('http://127.0.0.1:8080/?vid=500086').then((status)=>{
if(status !== 'success'){
console.log('Unable to access network');
}else{
checkReadyState(phInstance, page);
}
});
})
.catch(error => {
console.log(error);
phInstance.exit();
});
function onPageReady(phantom, page){
page.render('aaa' + Date.now() + '.pdf');
page.evaluate(function (){
return document.documentElement.outerHTML;
}).then((res)=>{
// TODO 缓存
console.log(res);
phantom.exit();
});
}
function checkReadyState(phantom, page){
setTimeout(function (){
page.evaluate(function (){
return document.querySelector('.video_list ul').innerHTML;
}).then((res)=>{
if("" != res.trim()){
onPageReady(phantom, page);
}else{
checkReadyState(phantom, page);
}
});
}, 5);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment