title: Puppeter Save returned value from page evaluate as a csv
body: <p>I currently have a puppeteer script, that fetches information from a website by getting an array of all hrefs on the page, looping through each href link, and then fetching the data from each respective href link.</p>
  <p>After using the page.evaluate function, I was able to return all desired values via return.</p>
  <p>How can I write the values of return in to a csv?</p>
  <p>Here is my script:</p>
  <pre><code>const stealth = require('puppeteer-extra-plugin-stealth')();
   
  
  
  const hrefsCategoriesDeduped = new Set(await page.evaluate(
      () =&gt; Array.from(
        document.querySelectorAll('.b-shared-linked-pharmacy__box a[href].b-shared-linked-pharmacy__details'),
        a =&gt; a.href
      )
    ));
  
  
    let pages = [];
  
  console.log (hrefsCategoriesDeduped)
  
  for (const url of hrefsCategoriesDeduped) {
  
      await page.goto(url);
     // await page.waitFor(10000)
      let telusData = {   
        name: &quot;&quot;,
        address: &quot;&quot;,
        city: &quot;&quot;,
        province: &quot;&quot;,
        postal: &quot;&quot;,
        fax: &quot;&quot;,
        pharmacyphone: &quot;&quot;,
        pharmacyfax: &quot;&quot;,
        pharmacyemail: &quot;&quot;,
        pharmacywebsite: &quot;&quot;
      };
      await page.waitForSelector('.b-pharmacy-detail__details');
      //let pharmacycomplete = []
  
      telusData =  await page.evaluate(() =&gt; {
   let pharmacyname  = document.querySelector('h2[class=&quot;b-pharmacy-detail__name&quot;]').innerText
   let pharmacystreet = Array.from(document.querySelectorAll(&quot;.b-pharmacy-detail__info&quot;), element =&gt; element.textContent)
   let pharmacyphoneandfax = Array.from(document.querySelectorAll(&quot;.b-pharmacy-detail__contact&quot;), element =&gt; element.textContent)
  
  var variable_names = {};
  for(var i = 0; i&lt; pharmacystreet.length; i++){
    variable_names['na_'+i] = pharmacystreet[i];
  }
  
  
  return {
    name: pharmacyname,
    address: pharmacyaddress,
    city1: city[1],
   province: province[1],
   postal: postal[1],
   pharmacyphone: pharmacyphone,
   pharmacyfax: pharmacyfax,
   pharmacyemail: pharmacyemail,
   pharmacywebsite: pharmacywebsite,
  
   }
  });
  
  console.log(telusData)
  
    }
  
  
  
      await browser.close();
    } catch (err) {
      console.error(err);
    }
  })();
  </code></pre>
  <p>Right now, I declare variable TelusData with all the headers for csv, then do a page evaluate to receive the value for the headers and the corresponding values.
  I return :</p>
  <pre><code>return {
    name: pharmacyname,
    address: pharmacyaddress,
    city1: city[1],
   province: province[1],
   postal: postal[1],
   pharmacyphone: pharmacyphone,
   pharmacyfax: pharmacyfax,
   pharmacyemail: pharmacyemail,
   pharmacywebsite: pharmacywebsite,
  
   }
  </code></pre>
  <p>For each 'telusdata' how can I save the values of the data into a csv with the headers as well? Any help is highly appreciated.</p>