Phantomjs元刷新重定向

时间:2015-11-25 15:15:07

标签: phantomjs

当页面有元刷新重定向时,我无法获取重定向到的页面内容。即使我使用setTimeout并等待10秒以确保加载最后一页,当我执行page.content时,我会在重定向之前获取页面的内容。

我能做点什么吗?

这是我的代码:

var mainUrl = "http://t.mobitrk.com/?a=t&aff_id=233&tags=df0a14a1-e673-4082-80c1-5283f4daa11cx&o_id=4879&sub_id=34753&sub_param1=xapnt20iix";


function makeRequest(url) {
    var page = require('webpage').create();
    page.settings.userAgent = "Mozilla/5.0 (Linux; Android 5.1.1; Nexus 5 Build/LMY48I) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.84 Mobile Safari/537.36";

    page.onNavigationRequested = function(url, type, willNavigate, main) {
        console.log(url);
    }


    page.open(url, function (status) {
        setTimeout(function() {
            console.log(page.content);
            phantom.exit(0);
        }, 10000);
    });
}


makeRequest(mainUrl);

结果是:

http://t.mobitrk.com/?a=t&aff_id=233&tags=df0a14a1-e673-4082-80c1-5283f4daa11cx&o_id=4879&sub_id=34753&sub_param1=xapnt20iix
http://app.appsflyer.com/com.groboot.yala?af_prt=fatal2&pid=clicksmob_int&clickid=cB_1448464013_76df1e4d78bf14572c7fe12cafb39f4d_wP&af_siteid=233&advertising_id=&af_sub1=34753
market://details?id=com.groboot.yala&referrer=af_tranid%3DC8KDGS5KXJ5BEQQ%26clickid%3DcB_1448464013_76df1e4d78bf14572c7fe12cafb39f4d_wP%26af_prt%3Dfatal2%26af_siteid%3D233%26pid%3Dclicksmob_int%26af_sub1%3D34753%26advertising_id%3D
<!DOCTYPE html><html><head><meta http-equiv="refresh" content="0;URL=http://app.appsflyer.com/com.groboot.yala?af_prt=fatal2&amp;pid=clicksmob_int&amp;clickid=cB_1448464013_76df1e4d78bf14572c7fe12cafb39f4d_wP&amp;af_siteid=233&amp;advertising_id=&amp;af_sub1=34753"></head><body></body></html>

如您所见,page.content包含第一个链接的内容。

0 个答案:

没有答案