OsiriX OsiriX - 3 months ago 61
JSON Question

Extract multiple occurrences in JSON file with iMacros

I'm using iMacros for Firefox and want to extract some id's from a JSON file. The JSON file looks like this:

"count":0,"id":"12345","time"
blabla
"count":0,"id":"12346","time"


The code I'm using in iMacros is:

URL GOTO=https://www.jsonurl.com
SEARCH SOURCE=REGEXP:"\"id\":\"(.[^\"]*)\"" EXTRACT="$1"
PROMPT {{!EXTRACT}}
SAVEAS TYPE=EXTRACT FOLDER=* FILE=*


With this code, it is only extracting 12345 from the above JSON example. How can I edit the code to extract all occurrences of id?

Answer

I would use JavaScript solution.

var macro;

macro ="CODE:";
macro +="URL GOTO=https://www.jsonurl.com"+"\n";
macro +="TAG POS=1 TYPE=DIV ATTR=CLASS:what_ever_you_are_extracting EXTRACT=HTM"+"\n";

iimPlay(macro)

var text=iimGetLastExtract();

text=text.split('"id":"')[1];
text=text.split('",')[0];

text=text.trim();

alert(text);

Edit:

The command

TAG POS=1 TYPE=HTML ATTR=CLASS:* EXTRACT=HTM

Extracts everything on the page.

Comments