首页 > Web开发 > 详细

php 模拟登陆(不带验证码)采集数据

时间:2017-12-16 20:20:50      阅读:279      评论:0      收藏:0      [点我收藏+]

技术分享图片

这里模拟表单登陆窗口

提交代码部分

1,生成session_id保存到 cookie

$login_url = ‘http://www.96net.com.cn/Login.php‘;
$cookie_file = dirname(__FILE__)."/pic.cookie";

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $login_url);

curl_setopt($ch, CURLOPT_HEADER, 0);

curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);

curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);

curl_exec($ch);

curl_close($ch);

2,处理提交的登陆的数据

if($_POST[‘acti‘]==‘tj‘){


$userid=$_POST[‘userid‘];
$password=$_POST[‘password‘];

$_post_url = ‘http://www.96net.com.cn/login.php?action=Login‘; //登录表单提交地址

$post = "userid=$userid&password=$password";

$ch12 = curl_init();

curl_setopt($ch12, CURLOPT_URL, $_post_url);

curl_setopt($ch12, CURLOPT_HEADER, false);

curl_setopt($ch12, CURLOPT_RETURNTRANSFER,1);

curl_setopt($ch12, CURLOPT_POSTFIELDS, $post); //提交方式为post

curl_setopt($ch12, CURLOPT_COOKIEFILE, $cookie_file);

curl_exec($ch12);

curl_close($ch12);

//以上表示登陆成功
//以下开始采集数据

$data_url19 = "http://www.96net.com.cn/xxxxxxx.php?id=10";     //数据所在地址

$ch19 = curl_init();

curl_setopt($ch19, CURLOPT_URL, $data_url19);

curl_setopt($ch19, CURLOPT_HEADER, false);

curl_setopt($ch19, CURLOPT_HEADER, 0);

curl_setopt($ch19, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch19, CURLOPT_COOKIEFILE, $cookie_file);

$content12 = curl_exec($ch19);

file_put_contents("./content0/31-35/net" . $k . ".txt", $content12); //文件存放的位置
}

php 模拟登陆(不带验证码)采集数据

原文:http://www.cnblogs.com/96net/p/8047384.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!