我正在尝试用 PHP 计算 Instagram 粉丝数。 (因为 JavaScript 不起作用)
我得到了这个 PHP 脚本,但它不起作用。
<?php
$url = 'https://www.instagram.com/cristiano/';
$str = file_get_contents($url);
$count = 0;
if(preg_match('#followed_by": {"count": (.*?)}#', $str, $match)) {
$count = $match[1];
} echo $count;
?>
答案 0 :(得分:1)
供您参考 ->>
1. Instagram 已将 #followed_by
更改为 #edge_followed_by
(来源:view-source:https://www.instagram.com/cristiano),这也是它回归 0 的原因之一。 >
2. 将“?__a=1”添加到 Insta Profile Url (https://www.instagram.com/cristiano/?__a=1) 即可获得 Json,只需解码 Json 即可获得值.
3.这些不是从 Instagram 获取信息的合法方式。我更喜欢使用Instagram API,它易于使用且免费。
更新
4. 或者您可以从 <meta>
标签而不是 <script>
标签获得关注者(示例 - <meta content="310m Followers, 476 Following, 3,095 Posts - See Instagram photos and videos from Cristiano Ronaldo (@cristiano)" name="description" />
)>