laravieira/scraping
Composer 安装命令:
composer require laravieira/scraping
包简介
Simple Web Scraping Framework, based on Curl and str* functions.
README 文档
README
Simple Web Scraping Framework, based on Curl and str* functions. Requires PHP ^8.0 (can easily be downgraded to PHP 7)
What you can do?
There is some functions to simplify your script, they are listed below:
Global functions
- upname => Format and return string to name formats (first each word character is uppercase)
- price => Return float value of and price string of type 'xx$: 9.999,99'
- accents => Replace accentuation with equivalent characters
- strmstr => Return string after start3, after start2, after start1
- strpart => Return middle string between start and end strings
- strmpart => Return middle string between start2 and end string, which start2 is after start1
Scrapping object
- Scrapping::cache => can save or return an cache
- Scrapping::cacheFolder => you can set a custom folder to cache
- Scrapping::json => parse and print the response in json
- Scrapping::isOnSession => tell if an session is set with server
- Scrapping::load => Reuse session of previews connections
- Scrapping::useSession => Set/Return if session setting is enabled
- Scrapping::userAgent => Set/Return userAgent
- Scrapping::server => Set/Return server host base URL
- Scrapping::session => Set/Return server session id
- Scrapping::hasSession => Returns if has a server session id set
- Scrapping::sesionName => Set/Retrun server session cookie name
- Scrapping::get => Make and return an get request to the server
- Scrapping::post => Make and return an post request to the server
- Scrapping::proccess => Proccess the get and post request to organaze data
How to use?
upname
upname(string $text);
Just pass the text string to format as parameter and the result will be the formated string. Some exemples bellow, the comment of each block represents the output:
Examples:
echo upname('lara vieira'); // 'Lara Vieira'
echo upname('LARA VIEIRA'); // 'Lara Vieira'
echo upname('LEONARDO DE CÁPRIO'); // 'Leonardo de Cáprio'
echo upname('DON PEDRO II'); // 'Don Pedro II'
price
price(string $text);
Just pass the text string to format as parameter and the result will be the float value. Some exemples bellow, the comment of each block represents the output:
echo price('US$: 3.567,56'); // 3567.56
echo price('R$: 3.456.234,45'); // 3456234.45
echo price('Price is R$: 234,45'); // 234.45
accents
accents(string $text);
Just pass the text to format as parameter and the result will be the formated string. An exemple bellow, the comment represent the output:
echo accents('Aglomeração, Apóstolo, vô, vó'); // 'Aglomeracao, Apostolo, vo, vo'
strmstr
strmstr( string $haystack, string $start1, string $start2, string|null $start3=null );
This function return all haystack string after start3 string that is after start2 string that is after start1 string (if start3 is passed) or all haystack string after start2 string that is after start1 string. The return will include the last start passed, like strstr.
This function is something like an stack of strstr functions:
strstr(strstr(strstr(haystack, start1), start2), start3)
Some exemples bellow, the comment of each block represents the output:
echo strmstr('ABC ABC ABC', 'C'); // 'C ABC ABC'
echo strmstr('ABC ABC ABC', 'B', 'A'); // 'ABC ABC'
echo strmstr('ABC ABC ABC', 'B', 'B', 'A'); // 'ABC'
strpart
* This is my favorite one for web-scrapping.
strpart( string $haystack, string|null $start = null, string|null $end = null, bool $keep_start = false );
This function will return the middle string in haystack between the first occurence of start string and the first occurence of end string after start string.
-
If
startstring is null, will return everything inhaystackbefore the first occurence ofendstring. -
If
endstring is null, will return everything inhaystackafter the first occurence ofstartstring. -
If
keep_startboolean is set totrue, default isfalse, the function will return as normal, but includingstartstring in the retrun's begin.
Some exemples bellow, the comment of each block represents the output:
echo strpart('ABC ABC ABC', ' ', ' '); // 'ABC'
echo strpart('ABC ABC ABC', ' '); // 'ABC ABC'
echo strpart('ABC ABC ABC', end:' '); // 'ABC'
echo strpart('ABC ABC ABC', ' ', ' ', true); // ' ABC'
echo strpart('<h2>Subtitle<h2>', '>', '<'); // 'Subtitle'
echo strpart('<div><div>Content</div></div>', '<div>', '</div>'); // '<div>Content'
strmpart
strmpart( string $haystack, string $start1, string $start2, string|null $end = null, bool $keep_start = false );
This function solve the last example of strpart.
This function will return the middle string in haystack between the first occurence of start2 string, that one is after the first occurence of start1 string, and the first occurence of end string after start2 string.
-
If
endstring is null, will return everything inhaystackafter the first occurence ofstart2string, after the first occurence ofstart1string. -
If
keep_startboolean is set totrue, default isfalse, the function will return as normal, but includingstart2string in the retrun's begin.
Some exemples bellow, the comment of each block represents the output:
echo strmpart('<div><div>Content</div></div>', '<div>', '<div>', '</div>'); // 'Content'
echo strmpart('<div><div>Content</div></div>', '>', '>', '<'); // 'Content'
echo strmpart('<a id="link1"><h2 id="text1">Content</h2></a>', '<h2', 'id="', '"'); // 'text1'
laravieira/scraping 适用场景与选型建议
laravieira/scraping 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 18 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 09 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 laravieira/scraping 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 laravieira/scraping 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 18
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 13
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: proprietary
- 更新时间: 2022-09-27