不浪费时间,请查看此代码:
$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); ?>
在URL中使用参数gp = mehulmohan,它应该返回如下内容:
539让他圈起来
检查与mehulmohan相关的此网址
但实际上,它返回空白。为什么呢?
请帮忙。所有其他社交媒体,如pinterest和twitter都会返回正确的结果,但Google+会返回空白。
注意事项:我已经解析了&#34; +&#34; URL中的符号与1次一样,它不接受XML,而是第二次。
&#34; +&#34; =%2B =%252B
答案 0 :(得分:1)
使用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;
}