dsgdfg30210
dsgdfg30210
2013-05-13 11:56

在PHP中使用Curl单击按钮并获得响应

已采纳

I am trying to link our page to another, but it is on the other side of a disclaimer warning. Before everyone gets on my case for trying to do something unethical, I am merely trying to make the link easy for my user to get to a page - I am NOT scraping any information or otherwise doing something shady!

The link I am having issues with is this: https://www.bcpao.us/asp/disclaimap.asp
I am trying to press this button:

<input type="submit" name="Answer" value="Accept"\>

Here is my php/curl code:

$agent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)"; 
$url = 'https://www.bcpao.us/asp/disclaimap.asp';
$ckfile = tempnam ("d:/temp", "CURLCOOKIE");

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_COOKIEJAR, $ckfile);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$data['Answer'] = "Accept";
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
// I have tried the following also:
// curl_setopt($ch, CURLOPT_POSTFIELDS, "Submit=Answer%Accept");


$output=@curl_exec($ch);
$info = @curl_getinfo($ch);

if(curl_errno($ch)){
  echo 'Curl error: ' . curl_error($ch);
}

curl_close($ch);
echo "output is:'" . $output . "'";
echo "<br>";
echo "info is:";
print_r($info);

When I run the script, I get the original page back (not the one the button links to.) Any help would be most appreciated!

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • dqalnwuci494308 dqalnwuci494308 8年前

    Take a look at the form tag:

    <form action="answer_disclaimap.asp" method="post" id="Form1">
    

    You use wrong URL to disclaimap.asp. Change it to answer_disclaimap.asp:

    $url = 'https://www.bcpao.us/asp/answer_disclaimap.asp';
    

    And use http_build_query():

    $data['Answer'] = "Accept";
    curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query($data) );
    
    点赞 评论 复制链接分享

相关推荐