iMacros: How do I change the content of text with a var? - imacros

I am pretty new to it and I can't find an answer to this.
So how do I change the text inside the text area?
TAG POS=2 TYPE=INPUT:TEXT FORM=NAME:mdeform ATTR=NAME:title CONTENT=sampletext
I want the macro to edit sampletext to mytext. How do I do that?
I also have another question.
The CONTENT will contain "part1.mp4"
How do I change it to "My video: part1"?
So basically the extension needs to get removed and some words will be added.
I thought about storing "My video" in a constant and then ".mp4" needs to get removed. (a constant because "My video" stays the same, only "part1" will be a different word each time.
How do I do that?
Thanks

You may try this:
SET myText My<SP>video:<SP>
SET !EXTRACT_TEST_POPUP NO
TAG POS=2 TYPE=INPUT:TEXT FORM=NAME:mdeform ATTR=NAME:title EXTRACT=TXT
SET sampleText EVAL("\"{{!EXTRACT}}\".replace(/\.mp4/,\"\")")
ADD myText {{sampleText}}
TAG POS=2 TYPE=INPUT:TEXT FORM=NAME:mdeform ATTR=NAME:title CONTENT={{myText}}

Related

Extract and Search a Column

I have a {{!COL4}} set previous in my script, but i need to make a validation if the specific value exists in the page.
I tried the following code but seems the format is wrong
SET !VAR4 EVAL("var q = '{{!EXTRACT}}'.match(/\\'{{!COL4}}'\\/ig); if (!q) MacroError(\"ERROR - NO RECORD FOUND\"); else 'FOUND';")
Ok i found the correct format, thanks anyway!
SET !VAR4 EVAL("var q = '{{!EXTRACT}}'.match('{{!COL4}}'); if (!q) MacroError(\"ERROR - NO RECORD FOUND IN FIND\"); else ('{{!COL4}}');")

imacros Extract all text without href

need help for extract text1,text2,text3 (i mean all text, sometimes until text9 in category)
<h4>Category:</h4>
<p>text1, text2, text3</p>
my imacros code just only extract text1
TAG POS=R1 TYPE=A ATTR=TXT:* EXTRACT=TXT
Q : how extract all text in category ?
Thanks
To expand on the JavaScript comment, this is how you could go about it:
ExtractCategory.js content
// Play the macro reading the category data
iimPlay("foo.iim");
// Get the last extracted value, i.e. the p content
var pContent = iimGetExtract();
// Parse the p using regex, first find a tag pairs and then drop the surrounding a tags
var result = pContent.match(/<a(.*?)<\/a>/g).map(function(val){
return val.replace(/<\/?a>/g,'').replace(/<a.+>/g,'');
});
// Pass the generated String to another macro to work with it
iimSet("passed_var", result);
iimPlay("bar.iim");
Next to ExtractCategory.js, foo.iim content
'Your previous code here, line #2 is just to find the right p in line #3 in a mockup html
TAG POS=1 TYPE=H4 ATTR=*
TAG POS=R1 TYPE=P ATTR=* EXTRACT=HTM
Next to ExtractCategory.js, bar.iim content
'Do whatever with the passed variable containing your formatted String
'This is just an output to show it
PROMPT {{passed_var}}
When you run ExtractCategory.js it will run your foo.iim code to extract the p content, parse it with regex (might want to be careful here, depending on what texts you are expecting this might break) and then pass the generated String on to another macro to do with it what you please.
Running this your result is text1,text2,text3 as desired.
Read up on http://wiki.imacros.net/iimSet() and http://wiki.imacros.net/iimPlay() if you need further information on how to use them.
This code, will extract the data in all the A tags inside the P tag, but there is a small setup you need to do, I use XPATH to get the path of the A tags.
Please install:
XPath Checker By Brian Slesinsky
or
how to find the xpath of an element (I would recommend the chrome console method)
with this you need to right click on the a tag and give View XPATH, this will give you an XPATH like
/x:html/x:body/x:p/x:a[2]
Then, after you get this X path you need to paste it in the Xpath value (Note you need to remove the x: from the above XPATH before pasting. Also note the number in the [] of the Xpath indicates the child number, since we use !LOOP to set the line number we ignore [2]) of the tag, refer the below code where I have done the same with the above Xpath
Note:
1. Please loop the imacros code according to the number of A tags you want to extract.
2. You also need to update the folder attribute of SAVEAS line, to your desktop path.
Code:
SET !LOOP 1
SET !ERRORIGNORE YES
TAG XPATH=(/html/body//p/a)[{{!LOOP}}] EXTRACT=TXT
SAVEAS TYPE=EXTRACT FOLDER=C:/Users/Test/Desktop/ FILE=output.csv

iMacros if Statement [Need help]

I'm currently trying to make an if/else statement, however i wont manage to get it working...
This is my code:
SET !ERRORIGNORE YES
URL GOTO=https://en.wikipedia.org/wiki/Main_Page
WAIT SECONDS=2
SET !VAR1 {{!URLCURRENT}}
PROMPT {{!VAR1}}
WAIT SECONDS=2
EVENT TYPE=CLICK SELECTOR="HTML>BODY>DIV:nth-of-type(4)>DIV:nth-of-type(2)>DIV:nth-of-type(2)>DIV>UL>LI:nth-of-type(3)>A" BUTTON=0
WAIT SECONDS=2
SET !VAR2 {{!URLCURRENT}}
PROMPT {{!VAR2}}
SET !VAR3 EVAL("var d=\"{{!VAR1}}\"; var s=\"{{!VAR2}}\" ; if (d==s) {var x=https://www.google.de/;}x; else {var y=https://www.youtube.com;} y;")
URL GOTO={{!VAR3}}
(the prompt is to see that the !VAR's are set correctly)
I'm trying to go to wikipedia as example, save the weblink as a VAR1, and go to another page, which i set to VAR2.
After that i want to compare them, and check them and choose if ,like in this case, they are different (which they obviously are) iMacros should go to youtube.
Somebody might help? I don't want to use .js with my iMacros, and i know it is possible, but i dont know how....
I used this code as reference:
REFERENCE LINK FOR THE FOLLOWING QUOTE AND CODE
One Example I quite like is the following: (I need to switch on the
Light in some Game between 20h-08h by pressing a Switch On/Off Button
on the Page. Then I use:)
SET Light EVAL("var d=\"{{!NOW:hh}}\"; if ((d>7)&&(d<20)) {var x=0;} else {var x=1;} x;")
TAG POS={{Light}} TYPE=IMG ATTR=SRC:http://website.com/images/b_light_on_off.gif
Okay, i got it working for me, added some comments on it
URL GOTO=https://en.wikipedia.org/wiki/Main_Page
WAIT SECONDS=1
'Set the VAR1 to the current url= https://en.wikipedia.org/wiki/Main_Page
SET !VAR1 {{!URLCURRENT}}
WAIT SECONDS=1
URL GOTO=https://en.wikipedia.org/wiki/Portal:Featured_content
WAIT SECONDS=1
'Set the VAR2 to the current url= https://en.wikipedia.org/wiki/Portal:Featured_content
SET !VAR2 {{!URLCURRENT}}
' 1.Now !VAR3 is our answer from the if statement
' 2.We need to assign the text from {{!VAR1}} to a var x,y,z,...
' In this case, we use the letter d and s, and assign text with \"....\" to the var
' 3.We check if d and s are equal by if (d==s), there is also not equal (d!=s)
' Or bigger(but only for numbers) (d>s) or smaller (d<s)
' 4.After the if we say what !VAR3 should become if the if statement is right
' This is done by creating a new var (in this case the x)
' However the output shall be again a text, so we assign x to https://www.google.de
' And do this by assigning text to a var with \"....\" so in this case {var x = \"https://www.google.de\";}
' 5.After that we add the else, if the statement was false, and assign x to the text, which should
' !Be VAR3 when the statement was wrong, and we do this again the same way so in this case {var x=\"https://www.youtube.com\";}
' 6. At the end we "call" x and tell that whatever x has become, it is now !VAR3
SET !VAR3 EVAL("var d=\"{{!VAR1}}\"; var s=\"{{!VAR2}}\" ; if (d==s){var x = \"https://www.google.de\";} else {var x=\"https://www.youtube.com\";} x;")
'checking if code worked (and it did)
URL GOTO={{!VAR3}}
'you can of course change the SET !VAR1 or !VAR2 to some text inside a page, or whatever you like

How to input random username in iMacros?

How can I input random username using iMacros? I wanna create a simple sign up bot that will use random username every time. Any suggestion please.
I use 2 methods for this:
1) Purely random strings for one time use only.
Use this line to generate a string where in this case i<6 means the length of the output string and * 25 means the length of the array of letters to choose from
SET !VAR1 EVAL("var letters = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','w','x','y','z']; var string = ''; for(var i = 0; i < 6; i++){string += letters[parseInt(Math.random() * 25)]}; string")
to use the string add {{!VAR1}} where you need the username like so:
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:createaccount ATTR=ID:FirstName CONTENT={{!VAR1}}
2) Use pre-generated strings from a text file (Can be generated manually or by a 'random name generator' online), this allows you to save credentials for future use.
Generate a file.csv where each line holds comma seperated info for one user. Info is accessed as {{!COL1}} for first item, 2 for second item etc'
SET !DATASOURCE C:\Temp\stackoverflow.csv
'where to start in the csv file
SET !LOOP 1337
SET !DATASOURCE_LINE {{!LOOP}}
EVENTS TYPE=KEYPRESS SELECTOR="#new_post>DIV>P>DIV>DIV" CHARS={{!COL1}}
EVENTS TYPE=KEYPRESS SELECTOR="#new_post>DIV>P>DIV>DIV" CHARS={{!COL2}}
stackoverflow.csv file example:
pika,chuu,easypassword123
wobbu,ffet,mypassword
chari,zard,123456
I hope this helped, this is also my first comment ever.

iMacros simple if else if tag has empty value set to default value

I am new to Imacros and simply trying to extract order information from a page and sometimes the order information contains a telephone number sometimes not.
I want to have a simple if else statement in imacros script to check if the phone number is null/ empty, if it is use my default phone number in its place, any help with this would be useful, thanks in advance
VERSION BUILD=8070701 RECORDER=CR
SET !ERRORIGNORE YES
SET !TIMEOUT_PAGE 10
SET !TIMEOUT_TAG 0
TAB T=1
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:frmSubmit ATTR=ID:dayphone2 EXTRACT=TXT
SET !VAR7 {{!EXTRACT}}
SET !EXTRACT NULL
'THIS IS THE ACTION I NEED - NOT IN THE CORRECT IMACROS FORMAT
if (VAR7 == NULL) { SET !VAR7 = '0800 00097777}
I need VAR7 set to my default phone number if the value is empty from the extraction
thank for looking
With command "EVAL" it's a simple thing:
SET !VAR7 EVAL("if (\"{{!VAR7}}\" == 'NULL') '0800 00097777'; else \"{{!VAR7}}\";")
Check only that !VAR7 is really NULL, but not "" (for example).