juanparati/phpscraper
Composer 安装命令:
composer require juanparati/phpscraper
包简介
A PHP scraper
README 文档
README
1. What is it?
A command line tool used for extract and format content from webpages. It's suitable for extract like:
- product catalogs
- reviews
- lists
- etc
The output is formatted as JSON lines.
2. How it works?
-
Create a scraper receipt (see recipes)
-
Type:
phpscraper config url
The following example will extract all the reviews with the user name, comment and rating from Amazon:
phpscraper recipes/amazon.yml https://www.amazon.de/product-reviews/B000J34HN4/ref=acr_dpx_hist_3?ie=UTF8
For see additional options just type:
phpscraper --help
3. Recipes
Recipes are YML files that describe in a structure way how to extract the content from the pages. The recipes uses XPath routes in order to instruct which elements are extracted.
Example of recipe that extract comments from Amazon reviews:
project: "Amazon reviews extractor"
pagination:
next_xpath: "//li[@class='a-last']/a/@href"
extraction:
product:
xpath: "//h1/a[@class='a-link-normal']"
extract_as: "product"
in_memory: true
comments:
xpath: "//div[@class='a-section celwidget']"
subelements:
product:
from_memory: "product"
extract_as: "product"
name:
xpath: "//span[@class='a-profile-name']"
extract_as: "name"
rate:
xpath: "//i[contains(@class, 'a-icon-star')]/span"
extract_as: "rating"
extract_regex: "/^.{0,3}/"
cast_as: float
comment:
xpath: "//span[@class='a-size-base review-text review-text-content']"
extract_as: "comment"
verified:
xpath: "//span[@class='a-size-mini a-color-state a-text-bold']"
extract_as: "verified"
cast_as: boolean
3.1 The pagination section
It defines where the "next page" button is located. In case that this element is not found then scraper then it will finish the process until the current page is extracted.
3.2 The extraction section
It defines which elements are going to be extracted. It uses a cascade structure so its possible to define the parent and child elements.
The possible instructions for the extraction section are:
- xpath: It defines the element that is going to be extracted using a XPath expression. The expression will become automatically relative to the parent element if exists.
- subelements: It defines the child elements.
- extract_as: This is always required and it sets the field name of the element to extract.
- extract_regex: Regular expression used for extract the extracted content.
- cast_as: Cast the extracted data, so the JSON output will reflect the right data type. Possible casts are "boolean", "int", "float" and "string"
- in_memory: It used when we want to save temporally in the memory so we can use for example inside of another extraction thread.
5. Installation
PHPscraper can be installed in different ways:
A) Download the last build from Github or B) Just type "composer global require juanparati/phpscraper"
5. How to build my own package:
-
Download Caveman (The Mamuph Helper Tool)
-
Clone this project
-
Inside the project directory type:
caveman build . -x -r
juanparati/phpscraper 适用场景与选型建议
juanparati/phpscraper 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6 次下载、GitHub Stars 达 1, 最近一次更新时间为 2019 年 11 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 juanparati/phpscraper 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 juanparati/phpscraper 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 6
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-11-17