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?

有帮助吗?

解决方案 2

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.

其他提示

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)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top