Imacros extracting - imacros

Ji, just a quick question:
Why does that not working properly?
var extract = iimGetLastExtract();
if (extract == "#EANF#") {
break;
};
var extractMacro = "CODE:";
extractMacro += "SAVEAS TYPE=EXTRACT FOLDER=* FILE=scraper.txt" + "\n";
var retcode = iimPlay(extractMacro);
So i want to check if last extract is null and if it is, then break the loop. I want to save !extract to file too, but im getting blank "".
Thats my scraping .iim
TAB T=1
TAG POS=1 TYPE=A ATTR=ONMOUSEDOWN:return<SP>rwt(this,'','','','{{i}}','* extract=href

Try the below code/logic, it should work
iimPlay("CODE:TAG POS=1 TYPE=A ATTR=ONMOUSEDOWN:return<SP>rwt(this,'','','','{{i}}','* extract=href);
var extract = iimGetLastExtract();
while (extract != "#EANF#")
{
iimSet("extract",extract);
iimPlay("CODE:ADD !EXTRACT {{extract}}\n SAVEAS TYPE=EXTRACT FOLDER=* FILE=scraper.txt");
}

Related

How to add text "Before" Extracted Text?

I tried to collect data myself on social media, and I want to add text before the extract results.
Hire My Code :
VERSION BUILD=9030808 RECORDER=FX
SET !ERRORIGNORE YES
SET !EXTRACT_TEST_POPUP NO
TAB T=1
TAG POS=1 TYPE=STRONG ATTR=TXT:* EXTRACT=TXT
SAVEAS TYPE=EXTRACT FOLDER=C:\test FILE=extract.txt
TAG POS=1 TYPE=DIV ATTR=TXT:/* EXTRACT=TXT
SET !EXTRACT EVAL("var s = '{{!EXTRACT}}'.replace(/\\//, ''); s;")
SAVEAS TYPE=EXTRACT FOLDER=C:\test FILE=extract.txt
TAG POS=1 TYPE=SPAN ATTR=TXT:*#*.* EXTRACT=TXT
SAVEAS TYPE=EXTRACT FOLDER=C:\test FILE=extract.txt
TAG POS=1 TYPE=SPAN ATTR=class:_c24<SP>_2ieq EXTRACT=TXT
SET !EXTRACT EVAL("var s = '{{!EXTRACT}}'.replace(/Birth \\date/, ''); s;")
SAVEAS TYPE=EXTRACT FOLDER=C:\test FILE=extract.txt
I use this code to remove Special Character ̶"/̶"
SET !EXTRACT EVAL("var s = '{{!EXTRACT}}'.replace(/\\//, ''); s;")
I use this code because i want to remove unwanted text "B̶i̶r̶t̶h̶ ̶d̶a̶t̶e̶ 12 April 1992"
SET !EXTRACT EVAL("var s = '{{!EXTRACT}}'.replace(/Birth \\date/, ''); s;")
the results of the code :
Hilda
100992837
hilda8872#gmail.com
12 April 1992
Now... I want to add text to the results like this:
Name : Hilda
User ID : 100992837
Email : hilda8872#gmail.com
Date of Birth : 12 April 1992
What should I do ?
which one should i change?
please, this is my college assignment.
I tried use ADD !EXTRACT ..., but the result contains special characters.
ADD !EXTRACT Name<SP>:<SP>
TAG POS=1 TYPE=STRONG ATTR=TXT:* EXTRACT=TXT
SAVEAS TYPE=EXTRACT FOLDER=C:\test FILE=extract.txt
ADD !EXTRACT User<SP>ID<SP>:<SP>
TAG POS=1 TYPE=DIV ATTR=TXT:/* EXTRACT=TXT
SET !EXTRACT EVAL("var s = '{{!EXTRACT}}'.replace(/\\//, ''); s;")
SAVEAS TYPE=EXTRACT FOLDER=C:\test FILE=extract.txt
ADD !EXTRACT Email<SP>:<SP
TAG POS=1 TYPE=SPAN ATTR=TXT:*#*.* EXTRACT=TXT
SAVEAS TYPE=EXTRACT FOLDER=C:\test FILE=extract.txt
ADD !EXTRACT Date<SP>of<SP>Birth<SP>:<SP>
TAG POS=1 TYPE=SPAN ATTR=class:_c24<SP>_2ieq EXTRACT=TXT
SET !EXTRACT EVAL("var s = '{{!EXTRACT}}'.replace(/Birth \\date/, ''); s;")
SAVEAS TYPE=EXTRACT FOLDER=C:\test FILE=extract.txt
Result :
"Name : ","Hilda"
"User ID : ","100992837"
"Email : ","hilda8872#gmail.com"
"Date of Birth : ","12 April 1992"
SOLVED by Add this Code :
TAG POS=1 TYPE=STRONG ATTR=TXT:* EXTRACT=TXT
TAG POS=1 TYPE=INPUT:TEXT FORM=ACTION:/search/ ATTR=NAME:query CONTENT=Nama<SP>:<SP>{{!EXTRACT}}
SET !EXTRACT NULL
TAG POS=1 TYPE=INPUT:TEXT FORM=ACTION:/search/ ATTR=TXT:* EXTRACT=TXT
SAVEAS TYPE=EXTRACT FOLDER=C:\Users\CPS\Desktop FILE=extract.txt
Result :
Name : Hilda

How to skip Imacros row if keyword not found (CEO)

I'm scraping contact pages where appears word CEO.
Problem: When CEO is not mentioned my code wont compile.
Error:
RuntimeError: element * specified by Txt:CEO was not found, line 16 (Error code: -921)
My code: (it says When CEO appears on site scrape the next element.)
VERSION BUILD=8601111 RECORDER=FX
Tag Pos=1 Type=* Attr=Txt:CEO Content=Event:MouseOver
Tag Pos=R1 Type=* Attr=* Extract=Txt
Set CEO {{!Extract}}
Set !Extract Null
Set FinalVar Eval("var a = '{{CEO}}'; if (a != '#EANF#') { b = a; } else { b = 'Not found!'; } b;")
add !extract {{CEO}}
SAVEAS TYPE=EXTRACT FOLDER=D:\imacro\ FILE=ceos.csv
It can be useful to ignore any errors in the following way:
'...
SET !ERRORIGNORE YES
SET !TIMEOUT_STEP 0
Tag Pos=1 Type=* Attr=Txt:CEO Content=Event:MouseOver
Tag Pos=R1 Type=* Attr=* Extract=Txt
SET !TIMEOUT_STEP 6
SET !ERRORIGNORE NO
'...

iMacros to extract google results

I'm trying to extract google search results using iMacros, it does extracts the URL but instead of saving it redirected to extracted URL.
VERSION BUILD=10022823
TAB T=1
TAB CLOSEALLOTHERS
URL GOTO=https://www.google.com/?gws_rd=ssl
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:f ATTR=NAME:q CONTENT=Jhony
TAG POS=1 TYPE=BUTTON:SUBMIT FORM=NAME:f ATTR=NAME:btnG
'text input activated
TAG POS=1 TYPE=A ATTR=ONMOUSEDOWN:return* EXTRACT=HREF
SAVEAS TYPE=EXTRACT FOLDER=* FILE=links.csv
PROMPT {{!EXTRACT}}
SET !EXTRACT NULL
can anyone suggest what I'm doing wrong?
Perhaps, this could help:
TAB T=1
TAB CLOSEALLOTHERS
URL GOTO=https://www.google.com/?gws_rd=ssl
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:f ATTR=NAME:q CONTENT=Jhony
TAG POS=1 TYPE=BUTTON:SUBMIT FORM=NAME:f ATTR=NAME:btnG
TAG POS=1 TYPE=H3 ATTR=CLASS:"r" EXTRACT=HTM
SET !EXTRACT EVAL("'{{!EXTRACT}}'.match(/a href=\"(.*)\" onmousedown=/)[1];")
SAVEAS TYPE=EXTRACT FOLDER=* FILE=links.csv

iMacros / Select random photo from PC

I need to make iMacros to automatically choose random photo from a folder on my PC. How do I arrange it?
This is the line from iMacros for adding some file manually:
TAG POS=1 TYPE=INPUT:FILE FORM=ID:insta-add-image-form-all ATTR=ID:edit-insta-image-upload CONTENT=/path/to/the/specific/file
Thanks.
For Shugar
Here’s how my script looks like:
asd.iim
VERSION BUILD=8920312 RECORDER=FX
TAB T=1
URL GOTO=https://onlypult.com/dashboard
TAG POS=1 TYPE=A ATTR=TXT:Calendar
TAG POS=1 TYPE=A ATTR=TXT:+
TAG POS=1 TYPE=INPUT:FILE FORM=ID:insta-add-image-form-all ATTR=ID:edit-insta-image-upload CONTENT={{rndFilePath}}
TAG POS=1 TYPE=BUTTON FORM=ID:insta-add-image-form-all ATTR=ID:edit-nextsubmit--2
TAG POS=1 TYPE=BUTTON FORM=ID:insta-add-image-form-all ATTR=ID:edit-nextsubmit--3
TAG POS=1 TYPE=BUTTON FORM=ID:insta-add-image-form-all ATTR=ID:edit-saveimaage
asd.js
SET folderPath /path/to/folder/
SET rndFilePath EVAL("var arrFile = []; var file = Components.classes['#mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile); file.initWithPath('{{folderPath}}'); var filesEnum = file.directoryEntries; while (filesEnum.hasMoreElements()) {arrFile.push(filesEnum.getNext().QueryInterface(Components.interfaces.nsILocalFile).path);} arrFile[Math.floor(Math.random()*(arrFile.length))];")
PROMPT {{rndFilePath}}
Both files are in folder /iMacros/Macros.
When it comes to line with CONTENT={{rndFilePath}}, nothing happens.
Normally that line looks like this
TAG POS=1 TYPE=INPUT:FILE FORM=ID:insta-add-image-form-all ATTR=ID:edit-insta-image-upload CONTENT=/path/to/content.jpg
The thing is, I need to click and choose some file because there appears dropdown menu when I click on «upload from PC», I cannot just write copy-paste the path to the file. Is it possible?
If you’re using Firefox, the code below returns the full path to a random file from the folder ‘D:\Temp\img’ (specified with the ‘folderPath’ variable).
SET folderPath D:\\\Temp\\\img
SET rndFilePath EVAL("var arrFile = []; var file = Components.classes['#mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile); file.initWithPath('{{folderPath}}'); var filesEnum = file.directoryEntries; while (filesEnum.hasMoreElements()) {arrFile.push(filesEnum.getNext().QueryInterface(Components.interfaces.nsILocalFile).path);} arrFile[Math.floor(Math.random()*(arrFile.length))];")
PROMPT {{rndFilePath}}

Click a button if text exist in page with iMacros

I am trying to use iMacros with Firefox to click an UnFollow button ONLY if this code exist on the page...
<small class="follow-status">follows you</small>
If the above does not exist in the page source then it would run this iMacros code...
TAG POS=1 TYPE=DIV ATTR=TXT:UnFollow
From what I have read, there is no if/else type syntax but you can run Javascript with
EVAL("Javascript code here")
If anyone knows how I could do this I could really use the help
You can trick Imacros to make an If statement, but first you have to SET !ERRORIGNORE YES for this macro. Then:
SET EXTRACT NULL
'if this exist you extract the text(even if you know it)
'if doesn't exist should return error but we turned that off; Extract remains Null
TAG POS=1 TYPE=SMALL ATTR=TXT:follows<SP>you EXTRACT=TXT
SET !VAR1 EVAL("var text=\"{{!EXTRACT}}\"; if(text==\"follows you\") text = \"jibber\";else text = \"UnFollow\";text;")
'this one executes if the text is right, if not should give error but we turned that off
TAG POS=1 TYPE=DIV ATTR=TXT:{{!VAR1}}
Use a javascript file for this
run();
function run() {
var exists = doesElementExist();
alert('element exists? ' + exists);
if (exists) {
iimPlay('CODE: TAG POS=1 TYPE=DIV ATTR=TXT:UnFollow');
}
else {
// do something else here
}
}
// test if element exists
function doesElementExist() {
iimDisplay('looking for small element with class "follow-status" on page');
var code = iimPlay('CODE: SET !TIMEOUT_TAG 1\n'
+ 'TAG POS=1 TYPE=SMALL ATTR=CLASS:follow-status EXTRACT=TXT');
if (code !==1) {
return false;
}
var extract = iimGetLastExtract();
if (extract === '#EANF#') {
return false;
}
return true;
}