mad*_*php 7 javascript php curl
我正在使用cURL访问许多不同的页面.我想要一种优雅的方式来检查页面是否有javascript重定向.我可以检查window.location身体中是否存在a ,但因为它可能在.js文件中或使用像jQuery这样的库,所以似乎任何解决方案都不会是完美的.有人有主意吗?
感谢 Ikstar 指出 phantomjs 我制定了以下示例:
测试.js
var page = require('webpage').create();
var testUrls = [
"http://www.google.nl",
"http://www.example.com"
];
function testNextUrl()
{
var testUrl = testUrls.shift();
page.open(testUrl, function() {
var hasRedirect = page.url.indexOf(testUrl) !== 0;
console.log(testUrl + ": " + hasRedirect.toString());
if (testUrls.length) {
testNextUrl();
} else {
phantom.exit();
}
});
}
testNextUrl();
Run Code Online (Sandbox Code Playgroud)
结果:
D:\Tools\phantomjs-1.7.0-windows>phantomjs test.js
http://www.google.nl: false
http://www.example.com: true
Run Code Online (Sandbox Code Playgroud)