在外部网站上自动填写和提交表格


Auto fill and submit forms on external site

我想知道如何使用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上还有另一个表单也需要填写和提交。我想从本地服务器自动填写这两个表格。我该如何做到这一点?

最简单的方法是使用类似于greatemonkey(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; 
}