2013-07-02 84 views
3

我必須提交表單1000次才能爲網站創建對象。他們已經給我們提供了這樣的機會,但卻沒有簡單的方式來發布數據而不使用他們的網站形式。創建填充表單值並提交的腳本

形式有以下4個輸入:

Textbox name = login 
Textbox name = password 
select name = region (values from 1 to 2000) 
button name = submit 

有什麼辦法來創建一個腳本,將相應地選擇在瀏覽器中這些元素和設定值?

我想過使用AutoHotKey,但找不到任何方法來選擇Web元素並填寫它們的值。

<form method="post" autocomplete="off" action="index.php?authorized=1"> 

<input name="login" maxlength="12" type="text"> 

<input name="password" value="" maxlength="30" type="password"> 

<select name="local_id"> 
    <option value="1">Washington D.C.</option> 
    <option value="2">Chicago</option> 
    ...(many more that i removed) 
</select> 

<input name="login_id" value="223" type="hidden"> 
<input name="dss" value="1" type="hidden"> 
<input name="action" value="createUser" type="hidden"> 
<input name="submit" value="Submit" type="submit"> 

</form> 
+0

是的,這是可能的。你可以複製和粘貼源代碼爲

回答

2

您需要AutoHotkey_L(最新版本),然後才能使用Internet Explorer的COM接口。它甚至可以填寫表單,而不會顯示在屏幕上。

#NoEnv 
#SingleInstance Force 

; Settings 
path := "http://domain.tld/path/to/form.html" 

; Connect to IE 
wb := ComObjCreate("InternetExplorer.Application") 
wb.Visible := false 

; Load the page specified 
Load(wb, path) 

; Find the first form on the page (put 1 for the second, 2 for the third, etc.) 
Form := wb.Document.forms[0] 

; Fill in data and submit it 
Form["login"].value := "User" 
Form["password"].value := "sUp3rS3cUr3" 
Form["local_id"].value := "2" 
Form["submit"].click() 
return 

Load(wb, what) { 
    wb.Navigate(what) 
    while wb.Busy 
     continue 
    wb.Visible := true 
} 

然後你可以再初始頁面指示你的腳本Load,然後在更多的數據填寫,並再次提交。只需在其中放入一個while wb.Busy循環,以便php頁面可以完成。

+0

謝謝,我正在尋找的東西! – flip66

-1
<html> 
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script> //for jquery 
<head> 
<script> 
$(function(){ 
$('form').submit(function() 
{ 
for (a=0;a<1000;a++){ 
$(this).submit(); 
}; 
}); 
}); 
</script> 
</head> 
<body> 
<form> 
<input type='text' name='login' /><br /> 
<input type='password' name='password' /><br /> 
<select><script>$(function(){ for(a=0;a<=2000;a++){ $('select').prepend("<option>"+a+"</option>")}});</script> 
</select> 
<input type='submit' name='submit' /> 
</form> 
</body> 
</html> 

我沒有嘗試過一個,但你可以這樣給一個嘗試...只是一個想法,雖然因爲我還沒有嘗試過。

請糾正我的代碼,如果它是錯誤的(對於其他觀衆)。

+0

OP是問如何填充網站字段。不要自己寫 –