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}}');")
Related
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
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.
I have a search field filter on a docket_id or address like with wildcards before and after, on an orders table as below:-
if params.has_key?("docket_id_filter")
#orders = #orders.where("docket_id like ? OR address like ?", "%#{params[:docket_id_filter]}%", "%#{params[:docket_id_filter]}%")
end
I have a problem when users copy and paste a value in the search field with a "carriage return" or space after the number.
This returns no values as it doesn't match the criteria.
The code running on Rails for a correct search is as below:-
Started GET "/orders?utf8=%E2%9C%93&docket_id_filter=6140132790&state_filter=All&day_filter%5Bday%5D=&commit=Filter" for 127.0.0.1 at 2015-02-09 16:09:22 +0800
while one with an space after it, is as below:-
Started GET "/orders?utf8=%E2%9C%93&docket_id_filter=6140099196 &state_filter=All&day_filter%5Bday%5D=&commit=Filter" for 127.0.0.1 at 2015-02-09 16:13:45 +0800
How can I do a check to see the last character to exclude it? Do i use a ends_with or is there a way to ignore it or format the search field before running the code.
or
Can i check the last character and give an error pop-up msg?
Thanks in advance
Solved it! :-)
if params.has_key?("docket_id_filter")
if "docket_id_filter".last(0) == ''
#orders = #orders.where("docket_id like ?", "%#{params[:docket_id_filter].first(10)}%")
else
#orders = #orders.where("docket_id like ? OR address like ?", "%#{params[:docket_id_filter]}%", "%#{params[:docket_id_filter]}%")
end
end
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).
Excuse my ignorance.
I need to replace all data in a mysql field before and including the first # .
example field = golfers
data at the first hole the golfer missed a 9 inch putt and said "#hit it bad
new data hit it bad
update table set new_column_name = substring(column_name, instr(column_name, '#') + 1);