search
Homephp教程php手册PHP利用curl获取验证码(发送cookie二次抓取)

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

Jun 13, 2016 am 09:51 AM
cookiecurlphpsecondaryuseFunctionsendpowerfulcrawlofcodeObtainverify

php中curl功能的强大我想大家可能还不知道吧,下面我再介绍一个工作中用到的利用curl获取验证码的实例并且可以为造cookie.

 代码如下 复制代码

$CookieFile=tempnam("./tmep","beast");
if(isset($_GET["img"])){
$url = 'http://www.bKjia.c0m/phper/php.htm';//验证码code
$ch = curl_init($url);
curl_setopt($ch,CURLOPT_COOKIEJAR, $CookieFile);//把返回来的cookie信息保存在文件中
curl_exec($ch);
curl_close($ch);
exit();
}   
if(isset($_POST['d'])){
$b=$_POST[d];//验证码
$p="waybillNo=1721269381&inputcode=".$b;
$ch = curl_init();
// 2. 设置选项,包括URL
curl_setopt($ch,CURLOPT_URL, "http://www.bKjia.c0m");
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.bKjia.c0m);
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{
?>

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



?>
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.