ronnie/tra-crawler

一个用于爬取TRA网页收据并将数据以必要格式返回的包

v1.0.0-beta.2 2023-10-16 18:46 UTC

This package is auto-updated.

Last update: 2024-09-19 09:10:22 UTC


README

Logo

TRA爬虫

一个用于爬取TRA收据并将数据以集合、数组或JSON形式返回的PHP包。

徽章

从shields.io等地方添加徽章:shields.io

MIT License

安装

使用composer安装TRA爬虫。

  composer require ronnie/tra-crawler

该项目还使用了puppeteer来访问收据上的JS内容。

  npm install puppeteer

作者

用法/示例

纯PHP

当在纯PHP中使用此包时,以下简单设置可以帮助您开始

  use Ronnie\TRA\Crawler;
  
  ...
  
  $crawler = new Crawler();
  // For URI or QR Scanned receipts you can use the URI method
  $receipt = $crawler->setUri($yourURI)->crawl();

  // For Physical receipt, Receipt verification code and the time is to be used in conjuction with the code method
  $receipt = $crawler->setCode($yourCode, $yourTime)->crawl();

请注意,时间($yourTime)应采用hhMMss格式(124453)。

Laravel / 依赖注入

当在Laravel/Symfony项目或任何具有DI容器的项目中使用此包时,更好的解决方案是使用容器将Ronnie\TRA\Crawler类的实例注入到您需要的任何类或方法中。在这种情况下,单例效果最佳。

还可以扩展Ronnie\TRA\Crawler类或编写自己的实现,只要它们遵守Ronnie\TRA\Contracts\ResourceCrawler合同/接口。

本地运行

克隆项目

  git clone https://github.com/RonnieTaz/tra-crawler

进入项目目录

  cd tra-crawler

安装NPM依赖

  npm install puppeteer

安装Composer依赖

  composer install

使用CLI应用程序测试输出

  php bin/console app:test-output -i url -u the_receipt_url

此外,项目中已添加一些示例收据以简化测试。前往config.php设置您想要使用的示例。