1. Go to this page and download the library: Download revolution/salvager library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
revolution / salvager example snippets
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);
}
}
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
$page->close();
$browser->close();
use Revolution\Salvager\AgentBrowser;
use Revolution\Salvager\Facades\Salvager;
Salvager::agent(function (AgentBrowser $agent) use (&$url, &$text, &$html) {
$agent->userAgent('Chromium');
$agent->open('https://example.com/');
$agent->screenshot(config('salvager.screenshots').'agent-test.png');
$url = $agent->url();
$text = $agent->text('p:last-of-type', '--json');
$html = $agent->html('html');
// Run any agent-browser command
$result = $agent->run(command: '', args: '', options: '');
// If you are using a cloud provider, it is recommended not to close manually.
// $agent->close();
});
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.