4

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?

OsiriX
  • 390
  • 4
  • 19

2 Answers2

2

Sorry, no can do :(

Global, iterative matching is currently not supported, so only the first match on the page can be found and extracted.

Source (iMacros Wiki)

EdL
  • 415
  • 4
  • 12
1

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.

edinvnode
  • 3,497
  • 7
  • 30
  • 53
  • 1
    I'm getting the error: ReferenceError: iimGetLastExtact is not defined, line 9 (Error code: -991)? – OsiriX Feb 23 '14 at 17:54
  • var text=iimGetLastExtact(0); – Bestmacros Feb 23 '14 at 20:53
  • 1
    I edited and made the right code the letter "r" is missing in iimGetLastExtact(); – edinvnode Feb 23 '14 at 22:16
  • 1
    Thanks, got it working for normal html pages. But this json file doens't have the div and classes structure so I don't know what to fill in for ATTR=CLASS. – OsiriX Feb 24 '14 at 09:20
  • Is it a file on a link somewhere? Or on your hard drive? – edinvnode Feb 24 '14 at 12:38
  • It is a link to a facebook URL. I'm trying to scrape user ID's. – OsiriX Feb 24 '14 at 14:35
  • Download it on hard drive and use this to load that file http://stackoverflow.com/questions/21953736/imacros-read-text-file-using-javascript/21956427#21956427 – edinvnode Feb 24 '14 at 15:43
  • First, this is not possible because the content on the URL is constantly changing. Second: I don't see why this could be a solution? iMacros can read the json file, it just don't have structure like a normal html page with divs, id's and classes. – OsiriX Feb 24 '14 at 15:50
  • 1
    Can you give us exactly what you are extracting. This is command that works on all pages. TAG POS=1 TYPE=HTML ATTR=CLASS:* EXTRACT=HTM – edinvnode Feb 24 '14 at 15:55
  • Awesome! I used that command and now I got it working. Thanks a lot! – OsiriX Feb 24 '14 at 15:58