php - 为什么这是打印0?
问题描述
我正在尝试在 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;
?>
解决方案
供您参考->>
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" />
)
推荐阅读
- java - 如何创建供多个类使用的排序和排序参数类?
- c++ - 如何使程序对派生类对象使用函数重载
- java - 初学者作业需要帮助!扫描文件 -> 数据验证 -> 打印机
- python - 只下载网页的一部分;无论网页源中的位置如何
- python - Python Turtle for 循环无限运行
- unit-testing - 为 Neo4j 单元测试创建 MOCK UP 数据
- angular - Angular 7:使用 s3 键在循环内显示产品图像不起作用
- php - SMTP 邮件程序在 codeignitor 3 中不起作用
- qt - 如何获取 QML Action 快捷方式的平台原生字符串?
- python-3.x - 如何从少量输入图像生成更多图像用于训练?