簡體   English   中英

按鈕點擊事件后PhantomJS捕獲下一頁內容

[英]PhantomJS to capture next page content after button click event

我試圖在點擊方法后捕獲第二頁內容。 但它正在返回首頁內容。

const status = await page.open('https://www.dubailand.gov.ae/English/services/Eservices/Pages/Brokers.aspx');
console.log(status);
await page.evaluate(function() {
    document.querySelector('#ctl00_ctl42_g_26779dcd_6f3a_42ae_903c_59dea61690e9_dpPager > a.NextPageLink').click();
})

const content = await page.property('content');
console.log(content);

我通過使用puppeteer完成了類似的任務,但由於與puppeteer的部署問題而轉移到phantomjs。 任何幫助表示贊賞。

您獲得了首頁,因為您在單擊“下一步”按鈕后立即請求頁面內容,但您需要等待Ajax請求完成。 它可以通過觀察“樹掌”ajax加載器來完成:當它不可見時,結果就在。

// Utility function to pass time: await timeout(ms)
const timeout = ms => new Promise(resolve => setTimeout(resolve, ms));

// emulate a realistic client's screen size
await page.property('viewportSize', { width: 1280, height: 720 });

const status = await page.open('https://www.dubailand.gov.ae/English/services/Eservices/Pages/Brokers.aspx');

await page.evaluate(function() {
    document.querySelector('#ctl00_ctl42_g_26779dcd_6f3a_42ae_903c_59dea61690e9_dpPager > a.NextPageLink').click();
});

// Give it time to start request
await timeout(1000);

// Wait until the loader is gone
while(1 == await page.evaluate(function(){ 
    return jQuery(".Loader_large:visible").length 
}))
{
    await timeout(1000);
    console.log(".");
}

// Now for scraping
let contacts = await page.evaluate(function(){

    var contacts = []; 
    jQuery("#tbBrokers tr").each(function(i, row){
        contacts.push({"title" : jQuery(row).find("td:nth-child(2)").text().trim(), "phone" : jQuery(row).find("td:nth-child(4)").text().trim() })
    })

    return contacts;
});

console.log(contacts);

結果

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM