从 Instagram 抓取数据

Scraping data from Instagram

我实际上只需要 public 帐户的 关注者数量 , 例如 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 抓取数据时,我得到 nothing:

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;

查看此库:https://github.com/raiym/instagram-php-scraper 您可以获得关注者和关注者的数量,并获得几乎所有 public 无需授权即可在 Instagram 上共享的信息。

它基于我和社区发现的 JSON 回复,非常轻量级