我想知道如何使用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
上有另一个表单需要填写并提交。我想从我的本地服务器自动填写两个表单。我如何实现这一目标?
答案 0 :(得分:3)
最简单的方法是使用像greasemonkey(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;
}