Html 创建填写表单值并提交的脚本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17430997/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 10:41:17  来源:igfitidea点击:

Creating a script that fills in form values and submits

htmlpostautohotkey

提问by flip66

I have to submit a form 1000 times to create objects for a website. They have given us access to do so, but no easy way to POST the data without using their website's form.

我必须提交 1000 次表单才能为网站创建对象。他们给了我们这样做的权限,但不使用他们网站的表单就没有简单的方法来发布数据。

The form has these 4 inputs:

该表单有以下 4 个输入:

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

Is there any way to create a script that will select these elements in my browser and set values accordingly?

有什么方法可以创建一个脚本来在我的浏览器中选择这些元素并相应地设置值?

I thought about using AutoHotKey, but can't find any way to select web elements and fill in their values.

我想过使用 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>

采纳答案by Brigand

You'll need AutoHotkey_L (the most recently updated version), and then you can use the COM Interface for Internet Explorer. It can even fill in the forms, and not show up on your screen.

您将需要 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
}

You may then instruct your script to Loadthe initial page again, and then fill in more data, and submit again. Just put a while wb.Busyloop in there so the phppage can finish.

然后您可以再次将您的脚本指示到Load初始页面,然后填写更多数据,并再次提交。只需while wb.Busy在那里放一个循环,这样php页面就可以完成。

回答by o2kevin

<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>

I haven't tried that one but you may give this a try... Just an idea though cause I haven't tried it.

我还没有尝试过,但你可以尝试一下......虽然只是一个想法,因为我还没有尝试过。

Please correct my code if it's wrong.(for other viewers).

如果我的代码有误,请更正我的代码。(对于其他观众)。