不浪费时间,请查看以下代码:
$gp=$_GET["gp"];
function googleplus($gp) {
$furl = "http://query.yahooapis.com/v1/public/yql?q=SELECT * from html where url='https://plus.google.com/%252B".$gp."' AND xpath=\"//div[@class='Nn']//div[@class='rw Uc']//div[@class='Zi']//div[@class='V9b nhe']//div[@class='tQE8Kd BnqoOb']//div[@class='Qhb eZa']//div[@class='vkb']//p\"&format=xml";
$api = simplexml_load_file($furl);
$followers = $api->results->p;
return $followers;
}
好的。当我做
<?php echo googleplus($gp); ?>
在网址中使用参数gp = mehulmohan时,它应返回如下内容:
第539章有他在圈子里
检查此与mehulmohan相关的URL
但实际上,它返回空白。为什么?
请帮忙。所有其他社交媒体(如pinterest和Twitter)都返回正确的结果,但Google+返回空白。
需要注意的一点是:我已经在URL中两次解析了“ +”符号,就像在1次中一样,它不接受XML,而是第二次。
“ +” =%2B =%252B
使用正确编码URL中的字符urlencode()
。并记住始终将SimpleXML对象转换为字符串。更新后的函数如下所示:
function googleplus($gp) {
$furl = "http://query.yahooapis.com/v1/public/yql?q=SELECT * from html where url='https://plus.google.com/%252B".$gp."' AND xpath=\"//div[@class='Nn']//div[@class='rw Uc']//div[@class='Zi']//div[@class='V9b nhe']//div[@class='tQE8Kd BnqoOb']//div[@class='Qhb eZa']//div[@class='vkb']//p\"&format=xml";
$api = simplexml_load_file(urlencode($furl));
$followers = (string) $api->results->p;
return $followers;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句