Last active
March 28, 2017 11:21
-
-
Save lgh06/ec1b71ffaabaf9d4baa500f8236a9724 to your computer and use it in GitHub Desktop.
using phantom package.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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