简体   繁体   English

recaptcha图像和curl + PHP

[英]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; 找不到id recaptcha_image,尽管我echo $page; the webpage will be displayed and surprisingly even the recpatcha div (with the image itself). 该网页将被显示,甚至显示repatpatcha div(带有图像本身)。 Curl shouldn't load the image for recaptcha but somehow it does though when i try to find the div, it is not there. Curl不应该为recaptcha加载图像,但是尽管如此,当我尝试找到div时,它确实不存在。 Is there a way to capture the url of the recaptcha image? 有没有办法捕获Recaptcha图像的网址?

You'll want to use an HTML parser like this PHP Simple HTML DOM Parser . 您将要使用类似PHP Simple HTML DOM Parser这样的HTML解析器 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. 这首先获取页面,将其解析为脚本URL,然后为该挑战打开该URL,然后将其附加到URL本身。 The image will be in the $img variable. 该图像将在$img变量中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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