0

I have written a macro in JavaScript that uses iMacros (FireFox addon) to login to a website and extract a table. Eventually I want the data in a JavaScript array so that I can loop over it. iMacros extracts the table in a csv format. I have tried [Papa Parse][2] on the data (using the demo on its website) and the data was very usable after parsing. So I would like to incorporate PapaParse into my JavaScript code that uses iMacros. How would I do this?

I have tried pasting into my code the JavaScript code that is in this file: papaparse.min.js. This is the file the Papa Parse documentation says that you need for production. When I ran my JavaScript I got a reference error stating that "Papa" is not defined.

I am not trying to develop my own website. I am just trying to collect data from a table at another website. So I don't have an index.html file or any css files in my project.

Can I use Papa Parse with just JavaScript and iMacros?

Here is my code (papaparse.min.js excluded for brevity):

    function test() {
        var macro;
        macro ="CODE:";
        macro +="SET !ERRORIGNORE YES" + "\n";
        macro +="URL GOTO=https://en.wikipedia.org/wiki/United_States_presidential_election,_2016 " + "\n";
        macro +="TAG POS=1 TYPE=TABLE ATTR=TXT:* EXTRACT=TXT " + "\n";

     var returnCode = iimPlay(macro);
     var table = iimGetLastExtract();

// Parse csv string
// var data = Papa.parse(table);

   var document = window.document;
     // contents of Papaparse.min.js inserted here, omitted for brevity

   alert(window.Papa);
   alert(JSON.stringify(window.Papa);  

}

  [1]: https://addons.mozilla.org/en-US/firefox/addon/imacros-for-firefox/
  [2]: http://papaparse.com/
GuitarViking
  • 165
  • 2
  • 12

1 Answers1

0

I suggest adding one useful line in your code:

var document = window.document;

/* here is the JavaScript code that is in this file: papaparse.min.js */

// and here is already the 'Papa' object
alert(window.Papa);

Hope it's pretty clear for you now :)

Shugar
  • 5,269
  • 1
  • 9
  • 9
  • Thanks for the help. Unfortunately, I am a new learner of JavaScript and it is not clear for me yet. I pasted in the code in paraparse.min.js and added your code. The alert said "[object Object]". So I added this line: 'code' alert(JSON.stringify(window.Papa)));'code' But I still did not get the data from the table, like I expected. Do you have more suggestions? – GuitarViking Nov 16 '16 at 14:57
  • Why didn't you try: `var data = window.Papa.parse(table);` ? – Shugar Nov 17 '16 at 12:52