Auto fill and submit forms on external site

折月煮酒 提交于 2019-12-18 13:36:42

问题


I was wondering how does one auto fill multiple forms (using bot/local server) on multiple pages of external site (PHP) using ajax or curl.

For example a site www.abc.com/index.php has a form <form> <input name='text'></form> which takes you to the www.abc.com/fst.php when the form is submitted and there is another form on www.abc.com/fst.php that needs to be filled and submitted too. I want to automatically fill both form from my local server. How do i accomplish that?


回答1:


The easiest way is to using something like greasemonkey ( https://addons.mozilla.org/en-US/firefox/addon/greasemonkey/ ), but the better solution is to use the firebug 'net' tab to capture the post sent when you fill out the form and repeat that post with 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; 
} 


来源:https://stackoverflow.com/questions/8741545/auto-fill-and-submit-forms-on-external-site

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