微信运动数据抓取(PHP)

“微信运动”能够向朋友分享一个包含有运动数据的网页,网页中就有我们需要的数据。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,然后打开微信运动点击我的主页,如下:

微信运动数据抓取(PHP)_第1张图片
微信运动

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

微信运动数据抓取(PHP)_第2张图片
fiddler

PHP代码部分

$getOpenid = '这里填写openid';
$getHeader = array(
     "Connection: keep-alive",
     "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
     "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",
     "Accept-Encoding: gzip, deflate",
     "Accept-Language: zh-CN,zh;q=0.8,en-us;q=0.6,en;q=0.5;q=0.4",
);
$url = 'https://hw.weixin.qq.com/steprank/step/personal?opendi=' . $getOpenid;
//初始化
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
//显示请求头
curl_setopt($ch, CURLOPT_HEADER, 1);
//头信息
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
//设置User-Agent
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');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//发送cookie
curl_setopt($ch, CURLOPT_COOKIE, '这里填写cookie');
$response = curl_exec($ch);
echo $response;

你可能感兴趣的:(微信运动数据抓取(PHP))