javascript - 从 Instagram 抓取数据

标签 javascript php instagram instagram-api yql

我其实只需要一个公众号的关注者数量, 例如https://www.instagram.com/kygomusic/

新的 Instagram 的 API 规则非常严格(并进行了讨论): 现在无法访问大多数常见应用的公共(public)内容。您需要一个未授予普通应用程序的 public_content 范围(?!)

public_content: This permission (public_content) is only granted to apps that enable brands, advertisers, broadcasters and publishers to discover public content. We do not grant access to apps that do not fall into these categories. Please review our documentation (https://www.instagram.com/developer/review) for more information.

所以我决定从 Instagram 抓取数据

一个选项是使用 file_get_contents() (PHP),它可以工作,但它会从我的服务器加载所有网站,而且非常繁重。所以我的第一个想法是使用YQL。我将它用于 Twitter 并且运行良好,但是当我从 Instagram 抓取数据时,我什么也得不到:

http://developer.yahoo.com/yql/console/?q=select%20*%20from%20html%20where%20url%3D'https%3A%2F%2Fwww.instagram.com%2Fkygomusic%2F'&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys

最佳答案

我看了一下你提交的页面,考虑到你不会加载图片或处理js,它并没有那么重。在检查时我发现他们有一个 json 来存储数据。

....“followed_by”:{“count”:924725}

我没有时间测试这个,但它应该可以工作,或者至少你明白使用它的意义。 CURL 可能是一个更好的选择,因为它可以处理多线程请求。

$url = 'https://www.instagram.com/kygomusic/';
$str = file_get_contents($url);
$count = 0;
if(preg_match('#followed_by": {"count": (.*?)}#', $str, $match)) {
     $count = $match[1]; // get the count from Regex pattern
} echo $count;

关于javascript - 从 Instagram 抓取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37993827/

相关文章:

javascript - React Redux 首次加载时存储为空

javascript - 简化多余的jquery代码

instagram - 如何避免instagram错误429已超过每小时最大请求数

javascript - 在特定时间间隔后运行 Instagram 代码

ios - Instagram 获取所有评论

javascript - 有没有办法在普通 Javascript 中存储先前单击的元素

javascript - 一次通过jquery调整多个图像的大小

php - 使用 Composer 在生产环境中安装 npm 和 Bower 包(即没有 devDependency)

php - 如何在 yii2 中的每个 $model->save() 函数之后运行自定义代码

php - 通过引用返回。返回变量周围的括号