问题
I currently use iMacro for Firefox for quick form filling with random letters.
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 < 11; i++){string += letters[parseInt(Math.random() * 25)]}; string")
EVENT TYPE=CLICK SELECTOR="#namex" BUTTON=0
EVENTS TYPE=KEYPRESS SELECTOR="#namex" CHARS="{{!var1}}"
Result is e.g. adionudmeai
.
I have a text file that containing one hundred thousand names in this format.
johny.hunter
tim.davies
emil.bernadette
I want to use this names instead of the random combinations with two additional random numbers at the end.
The end result should look like bill.cayne32
.
回答1:
Here is the code for random names with two additional random numbers at the end:
SET !DATASOURCE names.txt
SET linesInTxt 100000
SET rndLine EVAL("Math.floor(Math.random()*'{{linesInTxt}}') + 1;")
SET !DATASOURCE_LINE {{rndLine}}
SET !VAR1 EVAL("'{{!COL1}}' + Math.random().toString().substr(2, 2);")
回答2:
I Use pre-generated strings from a text/csv file (Can be generated manually or by a 'random name generator' online). 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'. Using this csv method allows you to split first/last names and use them for both info filling and for the desired username with a period in between.
SET !DATASOURCE C:\Temp\stackoverflow.csv
SET !LOOP 1337 'where to start in the csv file
SET !DATASOURCE_LINE {{!LOOP}}
EVENTS TYPE=KEYPRESS SELECTOR="#new_post>DIV>P>DIV>DIV" CHARS={{!COL1}}{{!COL2}}.{{!COL3}}{{!VAR1}}
stackoverflow.csv file example:
pika,chuu,easypassword123
wobbu,ffet,mypassword
chari,zard,123456
after {{!COL1}} you can insert your random {{!VAR1}} or just {{!LOOP}} if it doesn't have to be real random.
To get VAR1 to display numbers and not chars do:
SET !VAR1 EVAL("var letters = ['1','2','3','4','5','6','7','8','9','0']; var string = ''; for(var i = 0; i < 2; i++){string += letters[parseInt(Math.random() * 10)]}; string")
来源:https://stackoverflow.com/questions/31734028/fill-up-fields-with-random-names-with-imacro