码迷,mamicode.com
首页 > 微信 > 详细

微信运动数据抓取(PHP)

时间:2017-10-21 15:25:50      阅读:1071      评论:0      收藏:0      [点我收藏+]

标签:appid   qbc   get   api   初始化   nbsp   eth   verify   请求头   

“微信运动”能够向朋友分享一个包含有运动数据的网页,网页中就有我们需要的数据。url类似于:https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx7fa037cc7dfabad5&redirect_uri=http%3A%2F%2Fhw.weixin.qq.com%2Fsteprank%2Foauth%3Freturnurl%3Dhttp%253A%252F%252Fhw.weixin.qq.com%252Fsteprank%252Fstep%252Fpersonal%253Fopenid%253Do95gOt1TKSg3s05ibokCOGcjJ0Mc%26env%3D&response_type=code&scope=snsapi_base&state=a2lMqpEv-_tolyT2GzXy6Q&connect_redirect=1#wechat_redirect,其中有用于对于微信运动的唯一openid,打开fiddler进行抓包,首先打开fiddler,然后打开微信运动点击我的主页,如下:

技术分享

此时如果顺利的话,fiddler会有微信浏览器请求这个url时,请求头的各个信息。

技术分享

下面是代码部分:

 

 1 $getOpenid = ‘这里填写openid‘;
 2 $getHeader = array(
 3     "Connection: keep-alive",
 4     "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
 5     "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36 MicroMessenger/6.5.2.501 NetType/WIFI WindowsWechat QBCore/3.43.691.400 QQBrowser/9.0.2524.400",
 6     "Accept-Encoding: gzip, deflate",
 7     "Accept-Language: zh-CN,zh;q=0.8,en-us;q=0.6,en;q=0.5;q=0.4",
 8 );
 9 $url = ‘https://hw.weixin.qq.com/steprank/step/personal?opendi=‘ . $getOpenid;
10 //初始化
11 $ch = curl_init();
12 curl_setopt($ch, CURLOPT_URL, $url);
13 //显示请求头
14 curl_setopt($ch, CURLOPT_HEADER, 1);
15 //头信息
16 curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
17 //设置User-Agent
18 curl_setopt($ch, CURLOPT_USERAGENT, ‘Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36 MicroMessenger/6.5.2.501 NetType/WIFI WindowsWechat QBCore/3.43.691.400 QQBrowser/9.0.2524.400‘);
19 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
20 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
21 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
22 //发送cookie
23 curl_setopt($ch, CURLOPT_COOKIE, ‘这里填写cookie‘);
24 $response = curl_exec($ch);
25 echo $response;

 

微信运动数据抓取(PHP)

标签:appid   qbc   get   api   初始化   nbsp   eth   verify   请求头   

原文地址:http://www.cnblogs.com/caiji/p/7702722.html

(0)
(1)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!