'Pass value from main function into internal function node js

everyone I am trying to pass the value which I have taken in the variable getWebsite to the function await page.evaluate(() => {. I am using nodejs library puppeteer and this code is being used for scraping

async function getData(page) { // get data from url
    //regex to check if the last expression is .com or not
    const regexWebsite = new RegExp('(.*\.)(com,net,org,edu)$');

    for (let i = 2; i < 6; i++) {
        var getWebsite = await page.$eval('#pane > div > div > div > div > div:nth-child(7) > div:nth-child(' + i + ') > button > div > div > div.fontBodyMedium'[0], el => el.textContent);
        if (getWebsite == regexWebsite) {
            break;
        }
        else {
            continue;
        }
    }

    console.log(getWebsite);
    const results = await page.evaluate(() => {
        return ({
            scraper_job_id: new Date().getFullYear(),
            company: document.querySelectorAll('#pane > div > div > div > div > div > div > div > div > h1 > span:nth-child(1)')[0].textContent,
            address: document.querySelectorAll('#pane > div > div > div > div > div:nth-child(7) > div:nth-child(1) > button > div > div > div.fontBodyMedium')[0].textContent,
            website: getWebsite,
            created_at: new Date().getFullYear() + '-' + new Date().getMonth() + '-' + new Date().getDate() + ' ' + new Date().getHours() + ':' + new Date().getMinutes() + ':' + new Date().getSeconds(),
            updated_at: new Date().getFullYear() + '-' + new Date().getMonth() + '-' + new Date().getDate() + ' ' + new Date().getHours() + ':' + new Date().getMinutes() + ':' + new Date().getSeconds()
        })
    });

    // insert into db
    con.query('INSERT INTO google_businesses SET ?', results, function (err) {
        if (err) throw err;
        console.log(results.company, 'inserted');
    });

    return results;
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source