Maison > php教程 > php手册 > le corps du texte

PHP利用curl获取验证码,发送cookie二次抓取

WBOY
Libérer: 2016-05-25 16:44:53
original
1026 Les gens l'ont consulté

<?php
$CookieFile = tempnam("./tmep", "beast");
if (isset($_GET["img"])) {
    $url = &#39;http://www.phprm.com/&#39;; //验证码code
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_COOKIEJAR, $CookieFile); //把返回来的cookie信息保存在文件中
    curl_exec($ch);
    curl_close($ch);
    exit();
}
if (isset($_POST[&#39;d&#39;])) {
    $b = $_POST[d]; //验证码
    $p = "waybillNo=1721269381&inputcode=" . $b;
    $ch = curl_init();
    // 2. 设置选项,包括URL
    curl_setopt($ch, CURLOPT_URL, "http://www.phprm.com");
    curl_setopt($ch, CURLOPT_COOKIEJAR, $CookieFile);
    curl_setopt($ch, CURLOPT_COOKIEFILE, $CookieFile); //同时发送Cookie
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $p); //提交查询信息
    $s = curl_exec($ch);
    curl_close($ch);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "http://www.phprm.com");
    curl_setopt($ch, CURLOPT_COOKIEFILE, $CookieFile); //同时发送Cookie
    curl_setopt($ch, CURLOPT_COOKIEJAR, $CookieFile);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $p); //提交查询信息
    $bs = curl_exec($ch);
    echo $bs; //输出结果
    curl_close($ch);
} else {
?>
<form id="form1" name="form1" method="post" action=""> 
<img  src="?img=true" / alt="PHP利用curl获取验证码,发送cookie二次抓取 " ><!--由服务器端取图片内容并输出--> 
<input type="text" name="d"  /> 
<input type="submit" name="button" id="button" value="提交" /> 
</form> 
<?php
}
Copier après la connexion


文章地址:

转载随意^^请带上本文地址!

Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Recommandations populaires
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!