定制 ziming/laravel-scrapingbee 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

ziming/laravel-scrapingbee

Composer 安装命令:

composer require ziming/laravel-scrapingbee

包简介

A PHP Laravel Library for ScrapingBee

README 文档

README

Latest Version on Packagist Total Downloads

A PHP Laravel Package for ScrapingBee

If you wish to support my work you can use my referral link to create a free account, I get a small reward if you upgrade to a paid plan in the future.

Installation

You can install the package via composer:

composer require ziming/laravel-scrapingbee

You can publish the config file with:

php artisan vendor:publish --provider="Ziming\LaravelScrapingBee\LaravelScrapingBeeServiceProvider" --tag="laravel-scrapingbee-config"

This is the contents of the published config file:

return [
    'api_key' => env('SCRAPINGBEE_API_KEY'),
    'base_url' => env('SCRAPINGBEE_BASE_URL', 'https://app.scrapingbee.com/api/v1/'),
    'timeout' => env('SCRAPINGBEE_TIMEOUT', 140),

    'google_search_base_url' => env('SCRAPINGBEE_GOOGLE_SEARCH_BASE_URL', 'https://app.scrapingbee.com/api/v1/store/google'),

    'walmart_search_base_url' => env('SCRAPINGBEE_WALMART_SEARCH_BASE_URL', 'https://app.scrapingbee.com/api/v1/walmart/search'),
    'walmart_product_base_url' => env('SCRAPINGBEE_WALMART_PRODUCT_BASE_URL', 'https://app.scrapingbee.com/api/v1/walmart/product'),

    'amazon_search_base_url' => env('SCRAPINGBEE_AMAZON_SEARCH_BASE_URL', 'https://app.scrapingbee.com/api/v1/amazon/search'),
    'amazon_product_base_url' => env('SCRAPINGBEE_AMAZON_PRODUCT_BASE_URL', 'https://app.scrapingbee.com/api/v1/amazon/product'),
];

Usage

The Generic ScrapingBee Client

$scrapingBeeClient = Ziming\LaravelScrapingBee\LaravelScrapingBee::make();

$response = $scrapingBeeClient->blockAds()
    ->when(now()->weekOfMonth === 4, function (LaravelScrapingBee $scrapingBeeClient): LaravelScrapingBee {
        // if it is last week of the month, spam premium proxy to use up credits!
        return $scrapingBeeClient->premiumProxy();
    })
    ->jsonResponse()
    //->aiQuery('top 5 blog posts') // AI Query Feature!
    //->aiExtractRules(['title' => 'title of post', 'summary' => 'summary of post']) // AI Extract Feature!
    ->jsScenario([
        ['click' => '#button_id'],
        ['wait' => 1000],
        ['wait_for' => '#slow_div'],
        ['scroll_x' => 1000],
        ['scroll_y' => 1000],
        ['fill' => ['#input_1','value_1']],
        ['evaluate' => 'console.log(window);'],
])->get('https://www.scrapingbee.com')

Look at the source code of src/LaravelScrapingBee.php for the other methods (link below). Methods that return $this are chainable. An example is the blockAds() method you saw above. Meanwhile methods such as get(), post(), usageStatistics() returns you an Illuminate\Http\Client\Response object if no exceptions are thrown.

LaravelScrapingBee.php

If for some reason you prefer to set all parameters at once you may wish to use the setParams() or addParams() method. Take note that these methods simply takes in an array and sets the parameters as is. So for the methods that does something extra before setting the parameter you would have to do them yourselves now if you chose this path.

An example is shown below:

$scrapingBeeClient = Ziming\LaravelScrapingBee\LaravelScrapingBee::make();

$response = $scrapingBeeClient->setParams([
        'js_scenario' => json_encode([
            'instructions' => [
                ['click' => '#button_id'],
                ['wait' => 1000],
                ['wait_for' => '#slow_div'],
                ['scroll_x' => 1000],
                ['scroll_y' => 1000],
                ['fill' => ['#input_1','value_1']],
                ['evaluate' => 'console.log(window);']
            ]
        ]),
        'block_ads' => true,
        'json_response' => true,
    ])->get('https://www.scrapingbee.com')

The Google Search ScrapingBee Client

$googleSearchScrapingBeeClient = Ziming\LaravelScrapingBee\LaravelScrapingBeeGoogleSearch::make();

$response = $googleSearchScrapingBeeClient
    ->page(1)
    ->search('scrapingbee')
    ->get();

Look at the source code of src/LaravelScrapingBeeGoogleSearch.php for the other methods (link below).

LaravelScrapingBeeGoogleSearch.php

Walmart ScrapingBee Clients

The Walmart Search ScrapingBee Client

$walmartSearchScrapingBeeClient = Ziming\LaravelScrapingBee\LaravelScrapingBeeWalmartSearch::make();

$response = $walmartSearchScrapingBeeClient
    ->query('iPhone')
    ->minPrice(100)
    ->maxPrice(1000)
    ->fulfillmentType('in_store')
    ->fulfillmentSpeed('today')
    ->domain('walmart.ca')
    ->sortBy('price_low')
    ->page(2)
    ->get();

Look at the source code of src/LaravelScrapingBeeWalmartSearch.php for the other methods (link below).

LaravelScrapingBeeWalmartSearch.php

The Walmart Product ScrapingBee Client

$walmartProductScrapingBeeClient = Ziming\LaravelScrapingBee\LaravelScrapingBeeWalmartProduct::make();

$response = $walmartProductScrapingBeeClient
    ->productId('5491199371')
    ->domain('walmart.ca')
    ->deliveryZip('10001')
    ->storeId('3520')
    ->get();

Look at the source code of src/LaravelScrapingBeeWalmartProduct.php for the other methods (link below).

LaravelScrapingBeeWalmartProduct.php

Amazon ScrapingBee Clients

The Amazon Search ScrapingBee Client

$amazonSearchScrapingBeeClient = Ziming\LaravelScrapingBee\LaravelScrapingBeeAmazonSearch::make();

$response = $amazonSearchScrapingBeeClient
    ->query('iPhone')
    ->startPage(2)
    ->pages(3)
    ->device('desktop')
    ->currency('usd')
    ->country('gb')
    ->sortBy('average_review')
    ->get();

Look at the source code of src/LaravelScrapingBeeAmazonSearch.php for the other methods (link below).

LaravelScrapingBeeAmazonSearch.php

The Amazon Product ScrapingBee Client

$amazonProductScrapingBeeClient = Ziming\LaravelScrapingBee\LaravelScrapingBeeAmazonProduct::make();

$response = $amazonProductScrapingBeeClient
    ->query('ASIN')
    ->device('desktop')
    ->currency('usd')
    ->country('gb')
    ->get();

Look at the source code of src/LaravelScrapingBeeAmazonProduct.php for the other methods (link below). LaravelScrapingBeeAmazonProduct.php

YouTube ScrapingBee Clients

YouTube ScrapingBee Search Client

$youTubeScrapingBeeSearchClient = Ziming\LaravelScrapingBee\LaravelScrapingBeeYouTubeSearch::make();

$response = $youTubeScrapingBeeSearchClient
    ->search('Python Tutorial')
    ->get();

Look at the source code of src/LaravelScrapingBeeYouTubeSearch.php for the other methods (link below). LaravelScrapingBeeYouTubeSearch.php

YouTube ScrapingBee Metadata Client

$youTubeScrapingBeeMetadataClient = Ziming\LaravelScrapingBee\LaravelScrapingBeeYouTubeMetadata::make();
$response = $youTubeScrapingBeeMetadataClient
    ->videoId('rfscVS0vtbw')
    ->get();

Look at the source code of src/LaravelScrapingBeeYouTubeMetadata.php for the other methods (link below). LaravelScrapingBeeYouTubeMetadata.php

YouTube ScrapingBee Transcript Client

$youTubeScrapingBeeTranscriptClient = Ziming\LaravelScrapingBee\LaravelScrapingBeeYouTubeTranscript::make();
$response = $youTubeScrapingBeeTranscriptClient
    ->videoId('rfscVS0vtbw')
    ->language('es')
    ->transcriptOrigin('uploader_provided')
    ->get();

Look at the source code of src/LaravelScrapingBeeYouTubeTranscript.php for the other methods (link below). LaravelScrapingBeeYouTubeTranscript.php

YouTube ScrapingBee Trainability Client

$youTubeScrapingBeeTrainabilityClient = Ziming\LaravelScrapingBee\LaravelScrapingBeeYouTubeTrainability::make();
$response = $youTubeScrapingBeeTrainabilityClient
    ->videoId('rfscVS0vtbw')
    ->get();

Look at the source code of src/LaravelScrapingBeeYouTubeTrainability.php for the other methods (link below). LaravelScrapingBeeYouTubeTrainability.php

ChatGPT ScrapingBee Client

$chatGptScrapingbeeClient = Ziming\LaravelScrapingBee\LaravelScrapingBeeChatGpt::make();

$response = $chatGptScrapingbeeClient
    ->prompt('Explain why a career in web development is a bad choice')
    ->webSearch()
    ->countryCode('US')
    ->addHtml()
    ->get();

Look at the source code of src/LaravelScrapingBeeChatGpt.php for the other methods (link below).

LaravelScrapingBeeChatGpt.php

Testing

Currently, there are no tests as it uses credits. But if there are tests in the future, you can run the command below to execute the testcases.

composer test

Contributing

You may 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.

ziming/laravel-scrapingbee 适用场景与选型建议

ziming/laravel-scrapingbee 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11.46k 次下载、GitHub Stars 达 43, 最近一次更新时间为 2021 年 08 月 21 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「laravel-scrapingbee」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 ziming/laravel-scrapingbee 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 ziming/laravel-scrapingbee 我们能提供哪些服务?
定制开发 / 二次开发

基于 ziming/laravel-scrapingbee 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 43
  • Watchers: 2
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-08-21