微信运动数据抓取(PHP)
“微信运动”能够向朋友分享一个包含有运动数据的网页,网页中就有我们需要的数据。url类似于:http://hw.weixin.qq.com/steprank/step/personal?openid=用户的openid,其中有用于对于微信运动的唯一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;
一个勤勤恳恳码代码的码农,爱生活,爱代码!