truercm/laravel-webscrape 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

truercm/laravel-webscrape

最新稳定版本:1.3.0

Composer 安装命令:

composer require truercm/laravel-webscrape

包简介

Scrape web paged within Laravel application

README 文档

README

Webscrape

Scrape web pages with a Laravel application.

Installation

You can install the package via composer:

composer require truercm/laravel-webscrape

You can publish and run the migrations with:

php artisan vendor:publish --tag="laravel-webscrape-migrations"
php artisan migrate

You can publish the config file with:

php artisan vendor:publish --tag="laravel-webscrape-config"

This is the contents of the published config file:

return [

    /*
    |--------------------------------------------------------------------------
    | Webscrape models
    |--------------------------------------------------------------------------
    */
    'models' => [

        /*
        |--------------------------------------------------------------------------
        | Subject model holds the credentials, target_id and the final scraping result
        |--------------------------------------------------------------------------
        */
        'subject' => TrueRcm\LaravelWebscrape\Models\CrawlSubject::class,

        /*
        |--------------------------------------------------------------------------
        | Target model stores the remote target, authentication url and processing job
        |--------------------------------------------------------------------------
        */
        'target' => TrueRcm\LaravelWebscrape\Models\CrawlTarget::class,

        /*
        |--------------------------------------------------------------------------
        | TargetUrl model collects all URLs for the Target
        |--------------------------------------------------------------------------
        */
        'target_url' => TrueRcm\LaravelWebscrape\Models\CrawlTargetUrl::class,

        /*
        |--------------------------------------------------------------------------
        | Url Result model stores processed results
        |--------------------------------------------------------------------------
        */
        'result' => TrueRcm\LaravelWebscrape\Models\CrawlResult::class,
    ],

    /*
     |--------------------------------------------------------------------------
     | Selenium driver url
     |--------------------------------------------------------------------------
     */
    'selenium_driver_url' => env('SELENIUM_DRIVER_URL', null),
];

Laravel Webcrawler uses Selenium to crawl the pages, so make sure you have it installed.

Usage

This is a generic package, you would need to implement all the crawling steps yourself.

The high concept overview involves:

  1. Having a CrawlTarget - the model, containing the entry point to the list of pages you need to crawl
  2. Crawl subject - a model that connects the credentials with the crawl target

Once you have registered a target, you can:

  1. Initialize subject with credentials and target urls
  2. Start remote url crawling and processing the result
    $crawlSubject = \TrueRcm\LaravelWebscrape\Actions\StoreCrawlSubject::run([
        'model_type' => App\Models\User::class,
        'model_id' => 1,
        'crawl_target_id' => 1,
        'credentials' => ['values' => 'that would be piped', 'into' => 'crawl target'],
]);

and from here:

resolve($crawlSubject->crawlTarget->crawling_job)
    ->dispatch($crawlSubject);
  1. After the job is finished we have final result in CrawlSubject's result column
    $crawlSubject->result;

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 545
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-06-13