2012-01-05 113 views
3

我想知道如何使用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。我想自动从我的本地服务器填写这两个表单。我如何做到这一点?

回答

3

最简单的方法就是使用类似的Greasemonkey(https://addons.mozilla.org/en-US/firefox/addon/greasemonkey/),但更好的方法是使用萤火虫“net”的标签,以捕获发送后,当您填写表格并重复后的卷曲度(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; 
}