这里模拟表单登陆窗口
提交代码部分
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