Creating a 'robot' to fill form with some pages in

只谈情不闲聊 提交于 2019-12-29 13:30:13

问题


I want to implement an 'robot' that could automatically fill forms. Is there an solution when you can fill data on page for example,form1.html and submit it, wait to next page and submit with data on form2.html,and so on... In the end it should also 'click' on a button to get a file that the form creates.

I want this 'robot' would use some confidential information, so it cant be done using client side technologies.

I was thinking about PHP - building it as a web site-web service, so you could transfer data to a web address, or a Web Service in .Net.

If it's important,the site I want to fill automatically is runs with ASP.NET.

I kind a new here...Can anyone give some examples or tutorials doing this thing. If exist some technologies that I didn't mention here to realize it I would be glad trying them also.


回答1:


Forms work by posting data, so instead of making a robot that would type something into every field and click submit, you can just POST the data to the server.

First grab the form fields names, and the action of the form.

Then CURL:

//set POST variables
$url = 'http://domain.com/get-post.php';
$fields = array(
                        'lname' => urlencode($last_name),
                        'fname' => urlencode($first_name),
                        'title' => urlencode($title),
                        'company' => urlencode($institution),
                        'age' => urlencode($age),
                        'email' => urlencode($email),
                        'phone' => urlencode($phone)
                );

//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);

//execute post
$result = curl_exec($ch);

//close connection
curl_close($ch);

Snippet from this site.




回答2:


Use Selenium.

"Selenium automates browsers. That's it. What you do with that power is entirely up to you. Primarily it is for automating web applications for testing purposes, but is certainly not limited to just that. Boring web-based administration tasks can (and should!) also be automated as well."

See examples here.



来源:https://stackoverflow.com/questions/17270335/creating-a-robot-to-fill-form-with-some-pages-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!