简体   繁体   中英

recaptcha image and curl + php

$page = $curl->post($baseUrl.'/submit.php', array('url'=>$address,'phase'=>'1','randkey'=>$randKey[0],'id'=>'c_1'));
$exp = explode('recaptcha_image',$page);

The id recaptcha_image is not found although if i echo $page; the webpage will be displayed and surprisingly even the recpatcha div (with the image itself). Curl shouldn't load the image for recaptcha but somehow it does though when i try to find the div, it is not there. Is there a way to capture the url of the recaptcha image?

You'll want to use an HTML parser like this PHP Simple HTML DOM Parser . Something like this will work then:

<?php
$page = $curl->post($baseUrl.'/submit.php', array('url'=>$address,'phase'=>'1','randkey'=>$randKey[0],'id'=>'c_1'));
$html->load($page);
$ret = $html->find('script[src^=http://api.recaptcha.net/]',0);
$src = $ret->src;
//I'm not sure how you get an url with your library, so this might or might not work
$page = $curl->get($src);
preg_match("%challenge\ :\ '([a-zA-Z0-9-_]*)',%", $page, $matches);
$img = "http://api.recaptcha.net/image?c=".$matches[1];
?>

This first fetches the page, parses it for the script URL, then opens that URL for the challenge which is then appended to the URL itself. The image will be in the $img variable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM