restyler/instagram-php-scraper

此包已被废弃,不再维护。没有建议的替代包。

Profixied Instagram PHP Scraper。无需授权即可获取账户信息、照片和视频,通过智能代理均衡器。


README

浏览器中查看时Instagram图片损坏?(2021年4月)

查看 https://github.com/postaddictme/instagram-php-scraper/issues/903#issuecomment-827537360

由于绕过Instagram防火墙困难,此仓库包含RapidApi代理版本的Instagram爬虫 https://github.com/postaddictme/instagram-php-scraper

为什么不直接使用住宅代理呢?

即使是好的住宅代理也会被Instagram频繁封禁。此爬虫一般比仅使用住宅或移动代理加原爬虫效果更好,因为它使用大量高质量的代理,并且自动处理重试和响应质量控制。

RapidAPI订阅页面

https://rapidapi.com/restyler/api/instagram40

这是一个分支。如果您需要原版非Profixied版本的爬虫,请使用原包!https://github.com/postaddictme/instagram-php-scraper

RapidAPI代理处理均衡和智能绕过Instagram防火墙。目前仅代理了API的公共方法(不需要认证,例如分析公共账户及其帖子评论),因为Instagram可能会跟踪登录IP地址,并在代理均衡器切换IP地址时将您的账户标记为可疑。所以请谨慎使用withCredentials()。请参阅examples/getAccountByUsername.php和examples/getAccountMediasByUsername.php作为安全使用代理版本的示例。

代理方法

  • getAccount()
  • getAccountById()
  • getMedias()
  • getMediasByTag()
  • getMediaByUrl()
  • getMediaByCode()
  • getCurrentTopMediasByLocationId()
  • getCurrentTopMediasByTagName()
  • getLocationById()

依赖项

代码示例

通过Instagram用户ID获取账户信息

require_once 'vendor/autoload.php';

$instagram = new \InstagramScraper\Instagram(new \GuzzleHttp\Client());
$instagram->setRapidApiKey('YOUR-RAPID-API-KEY');
$account = $instagram->getAccountById(3);
echo $account->getUsername();

通过Instagram用户名获取账户媒体

$instagram = new \InstagramScraper\Instagram(new \GuzzleHttp\Client());
$instagram->setRapidApiKey('YOUR-RAPID-API-KEY');
$nonPrivateAccountMedias = $instagram->getMedias('kevin');
echo $nonPrivateAccountMedias[0]->getLink();

注意:不要使用此代理版本进行通过withCredentials()方法进行的认证调用,请使用原始爬虫!

这不会工作,并在代理爬虫中抛出异常

use Phpfastcache\Helper\Psr16Adapter;

$instagram = \InstagramScraper\Instagram::withCredentials(new \GuzzleHttp\Client(), 'username', 'password', new Psr16Adapter('Files'));
$instagram->login(); // will use cached session if you want to force login $instagram->login(true)
$instagram->saveSession();  //DO NOT forget this in order to save the session, otherwise have no sense
$account = $instagram->getAccountById(3);
echo $account->getUsername();

安装

使用Composer

composer require guzzlehttp/guzzle restyler/instagram-php-scraper

如果您没有Composer

您可以从这里下载:这里

示例

请参阅示例:这里