title: Formatting text scraped with headless chrome crawler
body: <p>The code below scrapes text from multiple elements on the page, however the text needs formatting (adding spaces etc) so that I'm able to use it elsewhere.</p>
  <p>I have some JavaScript (working in the browser console) that loops over the elements, adding their text to an array and then turning that into a string, which does what I want. Is that code that can be reused here? I'm not sure where/if I can add it?</p>
  <pre><code>const HCCrawler = require(&quot;headless-chrome-crawler&quot;);
  const CSVExporter = require(&quot;headless-chrome-crawler/exporter/csv&quot;);
  
  const FILE = &quot;result.csv&quot;;
  
  const exporter = new CSVExporter({
    file: FILE,
    fields: [&quot;response.url&quot;, &quot;response.status&quot;, &quot;result.text&quot;],
  });
  
  (async () =&gt; {
    const crawler = await HCCrawler.launch({
      maxDepth: 9999,
      exporter,
      allowedDomains: [&quot;example.com&quot;],
      // Function to be evaluated in browsers
      evaluatePage: () =&gt; ({
        text: $(&quot;h1, h2, p&quot;).text(),
      }),
      // Function to be called with evaluated results from browsers
      onSuccess: (result) =&gt; {
        console.log(result.result.h1);
      },
    });
    // Queue a request
    await crawler.queue(&quot;https://example.com&quot;);
  
    await crawler.onIdle(); // Resolved when no queue is left
    await crawler.close(); // Close the crawler
  })();
  </code></pre>