artmedia-llc / instagram-php-scraper
Instagram PHP 爬虫。获取账户信息、照片和视频,无需任何授权
v0.0.2
2022-08-13 22:52 UTC
Requires
- php: >=7.2
- ext-curl: *
- ext-json: *
- guzzlehttp/guzzle: ^7.0.1
- psr/simple-cache: ~1.0
Requires (Dev)
- guzzlehttp/guzzle: ^7.2
- phpfastcache/phpfastcache: ^7.1
- phpunit/phpunit: ^7.0
This package is not auto-updated.
Last update: 2024-09-23 07:57:32 UTC
README
这个库基于 Instagram 网页版本。我们开发它是因为现在很难获取一个批准的 Instagram 应用。目的是支持网页桌面和移动版本上的所有功能。
依赖项
代码示例
use Phpfastcache\Helper\Psr16Adapter; $instagram = \InstagramScraper\Instagram::withCredentials(new \GuzzleHttp\Client(), 'username', 'password', new Psr16Adapter('Files')); $instagram->login(); $account = $instagram->getAccountById(3); echo $account->getUsername();
某些方法不需要身份验证
$instagram = new \InstagramScraper\Instagram(new \GuzzleHttp\Client()); $nonPrivateAccountMedias = $instagram->getMedias('kevin'); echo $nonPrivateAccountMedias[0]->getLink();
如果您使用身份验证,建议缓存用户会话。在这种情况下,您不需要每次程序运行时都运行 $instagram->login()
方法
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();
使用代理进行请求
// https://docs.guzzlephp.org/en/stable/request-options.html#proxy $instagram = new \InstagramScraper\Instagram(new \GuzzleHttp\Client(['proxy' => 'tcp://:8125'])); // Request with proxy $account = $instagram->getAccount('kevin'); \InstagramScraper\Instagram::setHttpClient(new \GuzzleHttp\Client()); // Request without proxy $account = $instagram->getAccount('kevin');
安装
使用 composer
composer.phar require artmedia-llc/instagram-php-scraper phpfastcache/phpfastcache
或
composer require artmedia-llc/instagram-php-scraper phpfastcache/phpfastcache
如果您没有 composer
您可以在这里下载它 这里。
示例
请参阅示例 这里。
其他
Java 库: https://github.com/postaddictme/instagram-java-scraper