curl php 百度,phpcurl模拟登录百度首页
代碼如下:
*/$post_fields = array();$post_fields = preg_data($contents,'aid',$post_fields);$post_fields = preg_data($contents,'isphone',$post_fields);$post_fields['mem_pass'] = 'on'; //post 數據數組 記住我的登錄狀態$post_fields = preg_data($contents,'more_param',$post_fields);$post_fields = preg_data($contents,'need_coin',$post_fields);$post_fields = preg_data($contents,'need_pay',$post_fields);$post_fields = preg_data($contents,'next_target',$post_fields);$post_fields['password'] = 'password'; //post 數據數組 記住我的登錄狀態$post_fields = preg_data($contents,'pay_method',$post_fields);$post_fields = preg_data($contents,'psp_tt',$post_fields);$post_fields = preg_data($contents,'return_method',$post_fields);$post_fields = preg_data($contents,'return_type',$post_fields);$post_fields = preg_data2($contents,'safeflg',$post_fields);$post_fields = preg_data($contents,'skip_ok',$post_fields);$post_fields = preg_data($contents,'tpl',$post_fields);$post_fields = preg_data($contents,'tpl_ok',$post_fields);$post_fields['u'] = 'http://www.baidu.com/';$post_fields['username'] = 'username'; //post 數據數組 記住我的登錄狀態$post_fields['verifycode'] = '';$ch = curl_init();curl_setopt ($ch, CURLOPT_URL, $url);curl_setopt ($ch, CURLOPT_HEADER, 0);curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt ($ch, CURLOPT_POST, 1);curl_setopt ($ch, CURLOPT_POSTFIELDS, $post_fields);curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookdir);curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)");curl_setopt ($ch, CURLOPT_REFERER, "https://passport.baidu.com/?login&tpl=mn");curl_exec($ch);curl_close($ch);$url = "http://www.baidu.com/";$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_HEADER, 0);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_COOKIEFILE, $cookdir);curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)");curl_setopt ($ch, CURLOPT_REFERER, "http://www.baidu.com/n");$contents = curl_exec($ch);print_r($contents);die;curl_close($ch);exit;function preg_data($source,$chr,$array){preg_match('//i', $source, $matches);if(!empty($matches)) { $a = $matches[1];} else { die('Not found the '.$chr.'.');}$array[$chr]=$a;return $array;}function preg_data2($source,$chr,$array){preg_match('//i', $source, $matches);if(!empty($matches)) { $a = $matches[1];} else { die('Not found the '.$chr.'.');}$array[$chr]=$a;return $array;}?>
現在是無法訪問到登錄后的頁面 高手指教
回復討論(解決方案)
可能是網址轉向了
CURLOPT_FOLLOWLOCATION設置這個參數為TRUE試試看
CURLOPT_FOLLOWLOCATION設置這個參數為TRUE試試看
這個貌似不行啊
看不懂咋回事!!!
之前已經寫了python和c#的版本的了。
等我抽空,再弄個php版本的,模擬登錄百度,給你看看。
樓主問題解決了么
本條技術文章來源于互聯網,如果無意侵犯您的權益請點擊此處反饋版權投訴
本文系統來源:php中文網
總結
以上是生活随笔為你收集整理的curl php 百度,phpcurl模拟登录百度首页的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php加超链接不显示不出来,如何将图片作
- 下一篇: php5.2.3 zend3,windo