Search code examples
puppeteerapify

How to serialize form data of iframe with Apify


Ok,So I try to serialize a form data, but I get undefined Here is code:

 const frame = page.frames().find(frame => frame.url().includes('reservation'));
const aHandle = await frame.evaluateHandle('document'); 
const form= await aHandle.$eval('#reservationData', element => element.outerHTML);
var theform = await serialize(form);
console.log(theform);

Solution

  • I don't know how the function serialize looks like. Can you provide code of this function?

    But you can do it easily with frame.$eval(selector, pageFunction[, ...args]) and jQuery.

    const Apify = require('apify');
    
    ...
    
    await Apify.utils.puppeteer.injectJQuery(page);
    const frame = page.frames().find(frame => frame.url().includes('reservation'));
    const theForm = frame.$eval('#reservationData', (form) => $(form).serialize())
    console.log(theform);