ravelinodecastro / instagram-php-scraper
Instagram PHP Scraper. 获取账户信息、照片和视频,无需任何授权
v0.11.1
2021-01-31 08:56 UTC
Requires
- php: >=7.2
- ext-curl: *
- ext-json: *
- guzzlehttp/psr7: ^1.7
- psr/http-client: ~1.0
- psr/simple-cache: ~1.0
Requires (Dev)
- guzzlehttp/guzzle: ^7.2
- phpfastcache/phpfastcache: ^7.1
- phpunit/phpunit: ^7.0
- dev-any-proxy-api
- v0.11.1
- v0.11.0
- v0.10.1
- v0.10.0
- v0.9.14
- v0.9.13
- v0.9.12
- v0.9.11
- v0.9.10
- v0.9.9
- v0.9.8
- v0.9.7
- v0.9.6
- v0.9.5
- v0.9.4
- v0.9.3
- v0.9.2
- v0.9.1
- v0.9.0
- v0.8.35
- v0.8.34
- v0.8.33
- v0.8.32
- v0.8.31
- v0.8.30
- v0.8.29
- v0.8.28
- v0.8.27
- v0.8.26
- v0.8.25
- v0.8.24
- v0.8.23
- v0.8.22
- v0.8.21
- v0.8.20
- v0.8.19
- v0.8.18
- v0.8.17
- v0.8.16
- v0.8.15
- v0.8.14
- v0.8.13
- v0.8.12
- v0.8.11
- v0.8.10
- v0.8.9
- v0.8.8
- v0.8.7
- v0.8.6
- v0.8.5
- v0.8.4
- v0.8.3
- v0.8.2
- v0.8.1
- v0.8.0
- v0.7.2
- v0.7.1
- v0.7.0
- v0.6.1
- v0.6.0
- v0.5.9
- v0.5.8
- v0.5.7
- v0.5.6
- v0.5.5
- v0.5.4
- v0.5.3
- v0.5.2
- v0.5.1
- v0.5.0
- v0.4.8
- v0.4.7
- v0.4.6
- v0.4.5
- v0.4.4
- v0.4.3
- v0.4.2
- v0.4.1
- v0.4.0
- v0.3.5
- v0.3.4
- 0.3.3
- v0.3.2
- v0.3.1
- v0.3.0
- v0.2.6
- v0.2.5
- v0.2.4
- v0.2.3
- v0.2.2
- v0.2.1
- v0.2.0
- v0.1.4
- v0.1.3
- v0.1.2
- v0.1.1
- v0.1.0
- v0.0.6
- v0.0.5
- v0.0.4
- v0.0.3
- v0.0.2
- v0.0.1
- dev-dev-any-proxy-api
- dev-master
This package is auto-updated.
Last update: 2024-09-16 17:48:04 UTC
README
这个库基于 postaddictme 和 restyler 版本。区别在于我的版本可以与任何代理API关联。我决定构建这个版本,因为restyler版本在返回这样的消息:“您的当前计划BASIC的请求每月配额已用尽”并且它只能与一个代理API一起工作,而postaddictme版本不允许我们直接使用代理API。
依赖关系
只有以下方法可以使用代理API,因为它们不需要身份验证
- getAccount()
- getAccountById()
- getMedias()
- getMediasByTag()
- getMediaByUrl()
- getMediaByCode()
使用restyler的Rapid Api示例(点击此处订阅其Proxy API)
$instagram = new \InstagramScraper\Instagram(); $instagram->getProxyApiUrl('https://instagram40.p.rapidapi.com/proxy?url={instagram_url}'); // do not remove {instagram_url}, it is later replaced by the instagram endpoints $instagram->setHeaders(['x-rapidapi-key'=>'YOUR-RAPID-API-KEY']); // this is where you add your api key $nonPrivateAccountMedias = $instagram->getMedias('kevin'); echo $nonPrivateAccountMedias[0]->getLink();
使用scraperapi示例(点击此处订阅其Proxy API)
$instagram = new \InstagramScraper\Instagram(); $instagram->getProxyApiUrl('http://api.scraperapi.com?api_key=YOUR-SCRAPPER-API-KEY&url={instagram_url}'); // do not remove {instagram_url}, it is later replaced by the instagram endpoints $nonPrivateAccountMedias = $instagram->getMedias('kevin'); echo $nonPrivateAccountMedias[0]->getLink();
此库中还可以使用的其他方法是
- getProxyApiUrl('string') : 用于检查和确认您的Proxy API url是否已设置
- clearProxyApiUrl() : 如果您不再想使用代理API进行请求,则用于清除之前设置的url
- setHeaders($array): 用于设置头部,如果您想在代理API请求中添加它们
从这里,所有其他部分都与postaddictme库中的相同
代码示例
$instagram = \InstagramScraper\Instagram::withCredentials(new \GuzzleHttp\Client(), 'username', 'password'); $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 ravelinodecastro/instagram-php-scraper
或
composer require ravelinodecastro/instagram-php-scraper
如果您没有composer
您可以从这里下载。
示例
请参阅示例 这里。
其他
Java库: https://github.com/postaddictme/instagram-java-scraper