revolution/salvager
最新稳定版本:2.1.0
Composer 安装命令:
composer require revolution/salvager
包简介
Tiny WebCrawler for Laravel using Playwright
关键字:
README 文档
README
Tiny WebCrawler for Laravel using Playwright.
Version 2
Version 2 has been reworked as a simple package that depends on Playwright. It only implements minimal functionality, since you can use playwright-php/playwright directly.
Requirements
- PHP >= 8.3
- Laravel >= 12.x
Installation
composer require revolution/salvager
Install Playwright browsers:
vendor/bin/playwright-install --browsers
Or install Playwright browsers with OS dependencies:
vendor/bin/playwright-install --with-deps
Usage
The browser will be terminated when you exit Salvager::browse(), so please obtain any necessary data within the Salvager::browse() closure. The Page object cannot be used outside of Salvager::browse().
use Revolution\Salvager\Facades\Salvager; use Playwright\Page\Page; class SalvagerController { public function __invoke() { Salvager::browse(function (Page $page) use (&$url, &$text) { $page->goto('https://example.com/'); $page->screenshot(config('salvager.screenshots').'example.png'); $url = $page->url(); $text = $page->locator('p')->first()->innerText(); }); dump($url); dump($text); } }
If you want more control, just launch the browser with Salvager::launch().
use Playwright\Browser\BrowserContextInterface; use Revolution\Salvager\Facades\Salvager; /* @var BrowserContextInterface $browser */ $browser = Salvager::launch(); $page = $browser->newPage(); $page->goto('https://example.com/'); // Do something... // Don't forget to close the browser $browser->close();
LICENSE
MIT
统计信息
- 总下载量: 6.44k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-01-01