我想知道一种如何bot/local server使用ajax或curl在外部站点(PHP)的多个页面上自动填充多个表单(使用)。
bot/local server
例如,一个站点www.abc.com/index.php有一个表单<form> <input name='text'></form>,可将您带到www.abc.com/fst.php提交表单的时间www.abc.com/fst.php,而还有另一种表单也需要填写和提交。我想从我的本地服务器自动填写两个表格。我该如何做到?
www.abc.com/index.php
<form> <input name='text'></form>
www.abc.com/fst.php
最简单的方法是使用油脂类(https://addons.mozilla.org/en- US/firefox/addon/greasemonkey/)之类的方法,但是更好的解决方案是使用firebug的“ net”选项卡捕获发送的帖子当您填写表格并使用CURL(http://php.net/manual/en/book.curl.php)重复该帖子时
function post($url,$data) { $process = curl_init($url); curl_setopt($process, CURLOPT_HTTPHEADER, $this->headers); curl_setopt($process, CURLOPT_HEADER, 1); curl_setopt($process, CURLOPT_USERAGENT, $this->user_agent); if ($this->cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEFILE, $this->cookie_file); if ($this->cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEJAR, $this->cookie_file); curl_setopt($process, CURLOPT_ENCODING , $this->compression); curl_setopt($process, CURLOPT_TIMEOUT, 30); if ($this->proxy) curl_setopt($process, CURLOPT_PROXY, $this->proxy); curl_setopt($process, CURLOPT_POSTFIELDS, $data); curl_setopt($process, CURLOPT_RETURNTRANSFER, 1); curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($process, CURLOPT_POST, 1); $return = curl_exec($process); curl_close($process); return $return; }