地址: http://www.appannie.com/apps/ios/top/china/overall/?device=iphone
需要登录后才可以看到,怎么实现模拟浏览器登录?
1
zhzhwcn 2016-03-16 18:01:26 +08:00
Chrome 里开发人员工具里的 network 标签里看看有没有漏下的请求
|
2
jugelizi 2016-03-16 18:50:57 +08:00
你登录没 cookie 呀。。。。。。。
|
3
aswid OP @jugelizi 保存的 cookie 应该不对所以一直登录失败
cookie: # Netscape HTTP Cookie File # http://curl.haxx.se/docs/http-cookies.html # This file was generated by libcurl! Edit at your own risk. #HttpOnly_www.appannie.com FALSE / TRUE 0 sessionId ".eJxrYKotZNQI5S9OLS7OzM-LT81LTMpJTfFmChVIzEktKolPzkhNzo4vycxNLWRKTkksSQUxueCMQuZQLvYHzIJMvLwsnSLJBZUlVVzxoSHOXIUsmkGFrG1BhWyh3CX5xfGlBSA9KYXsnaV6AAqvJl4:1agNR3:N88XBiDLzuCkRN8ybuY5GhajWnU" .appannie.com TRUE / FALSE 1458180793 aa_user_token www.appannie.com FALSE / TRUE 1489630393 csrftoken nnMCiTASiomihPM9xqwgVzJep84jHacI |
4
aswid OP @zhzhwcn appannie 登录有 cookie 验证,cookie 不正确则无法登录成功,我保存的 cookie 有问题,不知道该怎么做
|
5
aswid OP <?php
function HttpsPost($url, $data = []) { $ch = curl_init(); //设置选项,包括 URL curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); //对证书来源的检查 curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5"); //模拟用户使用的浏览器 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); //使用自动跳转 curl_setopt($ch, CURLOPT_AUTOREFERER, 1); //自动设置 Referer curl_setopt($ch, CURLOPT_POST, 1); //发送一个 常规的 Post 请求 curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); //要提交的信息 curl_setopt($ch, CURLOPT_TIMEOUT, 30); //设置超时限制防止死循环 curl_setopt($ch, CURLOPT_HEADER, 0); //显示返回的 Header 区域内容 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //获取的信息以文件流的形式返回 curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__) . '/curl.cookie'); curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__) . '/curl.cookie'); $output = curl_exec($ch); //执行操作 if (curl_errno($ch)) { return "Errno" . curl_error($ch); //捕抓异常 } curl_close($ch); //关闭 CURL return $output; } //获取登录所需参数 $loginFormUrl = 'https://www.appannie.com/account/login'; //设置 cookie 保存路径 $loginForm = HttpsPost($loginFormUrl, []); $preg_csrfmiddlewaretoken = "/<input\s.*?name=\'csrfmiddlewaretoken\'.*?value=\'(.*?)\'.*?\/>/"; $preg_next = "/<input\s.*?name=\"next\".*?value=\"(.*?)\".*?\/>/"; preg_match($preg_csrfmiddlewaretoken, $loginForm, $match_csrfmiddlewaretoken); preg_match($preg_next, $loginForm, $match_next); //设置 post 的数据 $post['csrfmiddlewaretoken'] = $match_csrfmiddlewaretoken[1]; $post['next'] = isset($match_next[1]) ? $match_next[1] : '/apps/ios/top/china/games/'; $post['username'] = '***@***.com'; $post['password'] = '******'; $post['remember_user'] = 'on'; //提交登录 $loginPost = HttpsPost($loginFormUrl, $post);//未登录成功 //获取信息 $url2 = 'http://www.appannie.com/apps/ios/top/china/games/?device=iphone'; $iphone_china = HttpsPost($loginFormUrl); echo $iphone_china; |
6
ppto 2016-03-31 17:22:13 +08:00
php 内核代码在线查看工具, www.phpsourcechm.com 不用只为了看内核代码在本地装 ide 了 s
|