我在网上搜索了一段时间,现在无法获得关于Google+个人资料的关注者数量。
我现在的计划是使用file_get_contents获取网页代码,然后使用preg_match。
但是我第一次使用这个功能,我不知道如何使用它。我在网上看了一下,但我不明白。
模式非常简单。每千个上有一个带有句点/点(。)的数字,一个空格,然后是“追随者”这个词。
我如何将其表达为preg_match的模式?
我读了一些关于preg_replace的内容,然后我可以使用它来替换句点/点(。)。我是对的吗?
非常感谢!
此致
Selfster
答案 0 :(得分:0)
答案 1 :(得分:0)
它不是一种万无一失的方法,但它有效。
$test = file_get_contents("https://plus.google.com/+SundarPichai");
$res = preg_match_all("%\b([\.\,\d]+) followers%",$test, $output, PREG_SET_ORDER);
var_dump($output);
正则表达式"%\b([\.\,\d]+) followers%"
以非字母数字字符开头,而不是逗号和点(取决于本地化)。
我认为默认情况下它会回溯到美国人(这就是为什么有逗号),然后是空格和单词followers
答案 2 :(得分:0)
首先,您需要一个Google API密钥,然后它的工作原理如下:
id就像103382528845345115881
密钥如AIzaSyAqlZ1MJSGXMSs8a5WbfvLpZTGJeHLVc2w
https://www.googleapis.com/plus/v1/people/<id>?key=<key>
您需要的字段是:"circledByCount": 10,
使用的短信形式是这样的:
<?php
$followers = json_decode(file_get_contents($url), true);
$followers = isset($followers['circledByCount'])
? $followers['circledByCount'] : 0;
仅在关注者数量公开可见时才有效。