抓取不到html,curl和file_get_contents都抓不到,但是页面可以直接打开。

张海霖 2015-11-03 04:05:45
抓取不到html,curl和file_get_contents都抓不到,但是页面可以直接打开。

请教

网址如下
https:/count.taobao.com/counter3?keys=SM_368_dsr-1097280647,ICCP_1_522177046867&callback=jsonp107

为什么我怎么都抓不到内容呢,始终是空
...全文
332 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
q81999008 2015-11-03
  • 打赏
  • 举报
回复

<meta charset="utf-8">
<?php 
$ch = curl_init();
$url='https://count.taobao.com/counter3?keys=SM_368_dsr-1097280647,ICCP_1_522177046867&callback=jsonp107';
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);   
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,0);
curl_setopt($ch, CURLOPT_HEADER, 0);
$output = curl_exec($ch);
curl_close($ch);
preg_match_all("/(?:\()(.*)(?:\))/i", $output, $ok);
$str=$ok[1][0];
$str=str_replace('{"',"{",$str);
$str=str_replace('":',":",$str);
$str=str_replace(',"',",",$str);
//不会正则只能这样苦逼的替换了。。反正就是把他重构为json格式
$str=str_replace('{','{"',$str);
$str=str_replace(':','":',$str);
$str=str_replace(',',',"',$str);
$obj=json_decode($str);
var_dump($obj);
echo "这是你要的ICCP_1_522177046867:".$obj->ICCP_1_522177046867;
?>
txh027 2015-11-03
  • 打赏
  • 举报
回复
敢不敢下次提问标题起个好点的名字,自己不会玩扯函数不行
txh027 2015-11-03
  • 打赏
  • 举报
回复
更新:
<?php
//$jsonp=file_get_contents('https://count.taobao.com/counter3?keys=SM_368_dsr-1097280647,ICCP_1_522177046867&callback=jsonp107');

$jsonp='jsonp107({"SM_368_dsr-1097280647":{v:0,nv:100,m_UFB:0,m:4.89661,m_g:20.15,s_UFB:0,s:4.8744,s_g:31.49,c_UFB:0,c:4.87867,c_g:39.55,gp:100.00,ss:290159,hdr:true},"ICCP_1_522177046867":4915});';

preg_match_all('/\d{1,}/',$jsonp,$arr);
echo array_reverse($arr[0])[0];
txh027 2015-11-03
  • 打赏
  • 举报
回复
拿去玩吧,
<?php
//$jsonp=file_get_contents('https://count.taobao.com/counter3?keys=SM_368_dsr-1097280647,ICCP_1_522177046867&callback=jsonp107');

$jsonp='jsonp107({"SM_368_dsr-1097280647":{v:0,nv:100,m_UFB:0,m:4.89661,m_g:20.15,s_UFB:0,s:4.8744,s_g:31.49,c_UFB:0,c:4.87867,c_g:39.55,gp:100.00,ss:290159,hdr:true},"ICCP_1_522177046867":4915});';

preg_match_all('/\d{1,}}/',$jsonp,$arr);
echo trim($arr[0][0],'}');
张海霖 2015-11-03
  • 打赏
  • 举报
回复
引用 5 楼 xuzuning 的回复:
他不过是返回了一个供 jsonp 调用的函数: jsonp107({"SM_368_dsr-1097280647":{v:0,nv:100,m_UFB:0,m:4.89661,m_g:20.15,s_UFB:0,s:4.8744,s_g:31.49,c_UFB:0,c:4.87867,c_g:39.55,gp:100.00,ss:290159,hdr:true},"ICCP_1_522177046867":4914}); 截取圆括号中间的内容,用 json_decode 函数解码即可
$arr = json_decode($response, false); var_dump($arr); 结果$arr是Null
xuzuning 2015-11-03
  • 打赏
  • 举报
回复
他不过是返回了一个供 jsonp 调用的函数: jsonp107({"SM_368_dsr-1097280647":{v:0,nv:100,m_UFB:0,m:4.89661,m_g:20.15,s_UFB:0,s:4.8744,s_g:31.49,c_UFB:0,c:4.87867,c_g:39.55,gp:100.00,ss:290159,hdr:true},"ICCP_1_522177046867":4914}); 截取圆括号中间的内容,用 json_decode 函数解码即可
张海霖 2015-11-03
  • 打赏
  • 举报
回复
引用 2 楼 q81999008 的回复:

$ch = curl_init();
$url='https://count.taobao.com/counter3?keys=SM_368_dsr-1097280647,ICCP_1_522177046867&callback=jsonp107';
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);   
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,0);
curl_setopt($ch, CURLOPT_HEADER, 0);
$output = curl_exec($ch);
curl_close($ch);
echo  $output;
怎么取到这个4905,谢谢,在线等,马上结帖。 "ICCP_1_522177046867":4905
果酱很好吃 2015-11-03
  • 打赏
  • 举报
回复
试试 curl 设置下 CURLOPT_USERAGENT,浏览器标识
q81999008 2015-11-03
  • 打赏
  • 举报
回复

$ch = curl_init();
$url='https://count.taobao.com/counter3?keys=SM_368_dsr-1097280647,ICCP_1_522177046867&callback=jsonp107';
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);   
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,0);
curl_setopt($ch, CURLOPT_HEADER, 0);
$output = curl_exec($ch);
curl_close($ch);
echo  $output;
misaka去年夏天 2015-11-03
  • 打赏
  • 举报
回复
贴出你的代码来看看

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧