msankhala/parsehub-php
Composer 安装命令:
composer require msankhala/parsehub-php
包简介
Php wrapper classes for Parsehub REST api.
README 文档
README
ParsehubPhp
Parsehub REST api wrapper class. Use this class to communicate with parsehub. This class uses phphttpclient to communicate with parsehub and monoglog to make log entries about operation performed. See Uses section for log path and api url option.
installation
You can either download, clone this repo or install via composer:
composer require msankhala/parsehub-php
Features
- Uses phphttpclient class for making http requests.
- This class also support basic logging using monolog.
- This class use
PSR-0autoload.
Uses
Create Parsehub class Object to communicate with Parsehub, pass the api_key
to parsehub class constructor. You can optionally pass api_url and log_path
log file path as second and third arguments.
api_url default value https://www.parsehub.com/api/v2
log_path default value <repo-root>/log/parsehub.log
Autoload Parsehub class:
require_once __DIR__ . '/vendor/autoload.php'; use Parsehub\Parsehub;
In your controller you can use Parsehub class to get list of all the
parsehub projects and run object for a parsehub project and save
them in your db. When you get a parsehub project information you also get the
run_list of that project which you can store in your db.
Get Parsehub projects list:
$api_key = <your-api-key>; $parsehub = new Parsehub($api_key); $projectList = $parsehub->getProjectList(); echo $projectList;
or
$api_key = <your-api-key>; $api_url = 'https://www.parsehub.com/api/v2'; $log_path = 'path/to/parsehub.log'; $parsehub = new Parsehub($api_key, $api_url, $log_path); $projectList = $parsehub->getProjectList(); echo $projectList;
// Get project_token and run_token from DB. $project_token = <get project token from db> $run_token = <get project token from db>
Get particular Parsehub project, Pass the project_token:
$parsehub = new Parsehub($api_key); $project = $parsehub->getProject($project_token); echo $project;
Get Last ready run Data for a project:
$parsehub = new Parsehub($api_key); $data = $parsehub->getLastReadyRunData($project_token); print $data;
Get data for a particular run, Pass the run token:
$parsehub = new Parsehub($api_key); $data = $parsehub->getRunData($run_token); print $data;
Get a particular run, Pass the run token:
$parsehub = new Parsehub($api_key); $run = $parsehub->getRun($run_token); print $run;
Run a parsehub project:
$parsehub = new Parsehub($api_key); $options = array( // Skip start_url option if don't want to override starting url configured // on parsehub. 'start_url' => '<starting url at which crawling starts>' // Enter comma separated list of keywords to pass into `start_value_override` 'keywords' => 'iphone case, iphone copy' // Set send_email options. Skip to remain this value default. 'send_email' => 1, ); $run_obj = $parsehub->runProject($project_token, $options); echo $run_obj;
Cancel a parsehub project run:
$parsehub = new Parsehub($api_key); $cancel = $parsehub->cancelProjectRun($run_token); print $cancel;
Delete a parsehub project run, This will delete the project run and data of that run so be careful when using this method, once data deleted for a run, are not recoverable:
$parsehub = new Parsehub($api_key); $cancel = $parsehub->deleteProjectRun($run_token); print $cancel;
You can check the log in your log file.
msankhala/parsehub-php 适用场景与选型建议
msankhala/parsehub-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 12.41k 次下载、GitHub Stars 达 13, 最近一次更新时间为 2015 年 04 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「curl」 「http」 「rest」 「api」 「restful」 「parsehub」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 msankhala/parsehub-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 msankhala/parsehub-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 msankhala/parsehub-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
cURL and cURL based Soap-Client for PHP
repository php library
Simple cURL wrapper
A PSR-7 compatible library for making CRUD API endpoints
Api bundle
A fluent PHP CURL wrapper
统计信息
- 总下载量: 12.41k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 13
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-04-20