troubleshooting Question

Parsing output with VBS or JS

Avatar of Bryan71
Bryan71 asked on
Programming Languages-OtherWeb Languages and StandardsJavaScriptWeb Development SoftwareVB Script
51 Comments1 Solution1225 ViewsLast Modified:
I am trying to build a quick extract to regularly pull my companies facebook fans from the API. I am using iMacro and have written the code to pull one of our Facebook pages from a csv file/column 1, and then pull the fan name and id with the source url using regular expression and write it to a csv file (output: name, id, source url).

The place I am stuck (I am not a programmer) is that this is being pulled from the Facebook graph API and is not an html page so I can only get it to pull the first data pair. So, evidently I am being told what I have is correct so far but what needs to happen is that I need to have a VBS or JS that I actually launch that runs the macro script and then loops thru the graph api page pulling all data pairs and writes it to a csv file, then pulls the next row from my source csv file of our company pages, then parses the output, until there are no more source rows with a url. The script currently will pull either the first data pair using regex or the entire page of text as shown below but just writes the results  to the csv file not organized at all. Unfortunely with days of trial and is beyond my abilities.

So, here is a sample of the text that I am pulling that needs to be parsed. The only field I really need is the id paired with the source url (so I can keep track of the fans for each of our unique pages).

"data": [
"name": "Fan Name...",
"id": "123455767"
"name": "Fan Name...",
"id": "123455767555777"
"name": "Fan Name...",
"id": "1234557675656565"

Here is a sample of the code I have that actually pulls the first pair from the page and writes it to the csv file. I have another version of this code that does not use regex and can pull all of the text from the entire page, but then need to be parsed into the output file.


SET !DATASOURCE extract1.csv
'Number of columns in the CSV file.
'Start at line 2 to skip the headers in the file
'Increase the current position in the file with each loop

SEARCH SOURCE=REGEXP:"name":\s"([^"]+)" EXTRACT="$1"


SAVEAS TYPE=EXTRACT FOLDER=C:\Documents<SP>and<SP>Settings\admin\Desktop\folder1 FILE=extract1.csv

Here is a script I found that I am not using correctly since I don't understand how to do this.

Now, the solution as I understand it is that I need to launch a script that uses launches the imacro code and pulls all of the text, parses it and writes it to the csv file, then runs the imacro code again to pull the next source url, pulls the text and parses it...until there are no additional source urls then shuts down. Any help is appreciated as I have already burned up many hours trying to solve this before bothering anyone else...
Option Explicit

Dim iim1,iret
Set iim1 = CreateObject("imacros")
iret = iim1.iimInit("",FALSE) 'connect to open iMacros browser window 

Dim macro

Dim counter
counter = 1 

Dim extraction, extractionArray(5)

do while not (iret < 0)
   macro = "CODE:"
   macro = macro + "VERSION BUILD=7010818     "+vbNewLine
   macro = macro + "TAB T=1      "    + vbNewLine
   macro = macro + "TAB CLOSEALLOTHERS     "+vbNewLine
        macro = macro + "SET !EXTRACT_TEST_POPUP NO      "    + vbNewLine
        macro = macro + "SET !ERRORIGNORE YES      "    + vbNewLine
   macro = macro + "SET !DATASOURCE extract1.csv      "    + vbNewLine
                         'Number of columns in the CSV file. This must be accurate!
        macro = macro + "SET !DATASOURCE_COLUMNS 1      "    + vbNewLine
                         'Start at line 2 to skip the headers in the file
        macro = macro + "SET !LOOP 1      "    + vbNewLine
                         'Increase the current position in the file with each loop 
        macro = macro + "SET !DATASOURCE_LINE {{!LOOP}}      "    + vbNewLine
        macro = macro + "URL GOTO={{!COL1}}      "    + vbNewLine
        macro = macro + "SEARCH SOURCE=REGEXP:"name":\s"([^"]+)" EXTRACT="$1"      "    + vbNewLine
        macro = macro + "SEARCH SOURCE=REGEXP:"id":\s"(\d*)" EXTRACT="$1"      "    + vbNewLine
        macro = macro + "ADD !EXTRACT {{!URLCURRENT}}      "    + vbNewLine
        macro = macro + "SAVEAS TYPE=EXTRACT FOLDER=C:\Documents<SP>and<SP>Settings\admin\Desktop\folder1 FILE=results1.csv      "    + vbNewLine
   iret = iim1.iimPlay(macro)
   counter = counter + 3
   if (iret < 0) then
   end if

iret = iim1.iimPlay(macro)
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 51 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 51 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros