eelcol/laravel-scrapers

1.1.25 2024-05-29 15:19 UTC

README

一个使用 ScrapingBee 和/或 ScraperApi 爬取网页的 Laravel 扩展包。

示例

  • 爬取一个 URL
$response = Scraper::get('https://www.nu.nl');
  • 爬取一个图片
$response = Scraper::image('https://via.placeholder.it/250x250.png');
  • 使用特定的爬虫
$response = Scraper::provider('scraperapi')->get('https://www.nu.nl');
  • 使用高级代理
$response = Scraper::premium()->get('https://www.nu.nl');
  • 当编写触发爬虫的测试时,您可能不想使用 ScraperAPI 或 ScrapingBee。在这种情况下,将测试方法包含在您的测试中
...
Scraper::test();
...

安装

使用 composer 需要此包。

composer require eelcol/laravel-scrapers

添加到您的 env 文件中

SCRAPER_PROVIDER=see below
SCRAPER_MAX_CONCURRENCY=5
SCRAPERAPI_KEY=
SCRAPINGBEE_KEY=

当使用不同的代理时,将以下变量添加到您的 .env 文件中

SCRAPER_PROXY_HOST=
SCRAPER_PROXY_PORT=
SCRAPER_PROXY_USER=
SCRAPER_PROXY_PASS=

对于 SCRAPER_PROVIDER 允许以下值

  • scrapingbee
  • scraperapi
  • http
  • proxy

使用 http 进行常规 HTTP 请求,不使用爬虫提供者。使用 proxy 使用自定义定义的代理。