mitseo/scraper
Composer 安装命令:
composer require mitseo/scraper
包简介
Parse document with xpath,css selector and regex.
README 文档
README
This library helps you to parse data with different resources :
- Regex
- Xpath
- CSS Selector
Differents outputs are possibles :
- Match (match():boolean)
- Count elements (count():int)
- Extract first element (extractFirst():string)
- Extract all elements (extractAll():array)
Author : Mitsu
Installation with composer :
Add mitseo/scraper as a require dependency in your composer.json file:
composer require mitseo/scraper
Usage
Parse with Regex
use Mitseo\Scraper\Scraper; $string = "11111 222 33333 44444"; $regex1 = Scraper::regex("/[0-9]{5}/")->match($string); $regex2 = Scraper::regex("/([0-9]{5})/")->extractFirst($string); $regex3 = Scraper::regex("/([0-9]{5})/")->extractAll($string); $regex4 = Scraper::regex("/[0-9]{5}/")->count($string);
Parse with Xpath
use Mitseo\Scraper\Scraper; $dom = file_get_contents('https://en.wikipedia.com/'); $xpath1 = Scraper::xpath("//a")->match($dom); $xpath2 = Scraper::xpath("//a")->extractFirst($dom); $xpath3 = Scraper::xpath("//a")->extractAll($dom); $xpath3 = Scraper::xpath("//a")->count($dom); $xpath4 = Scraper::xpath("//a",["anchor"=>".","href"=>"@href"])->extractTree($dom);
Parse with CSS Selector
use Mitseo\Scraper\Scraper; $dom = file_get_contents('https://en.wikipedia.com/'); $css1 = Scraper::css("h1#truc")->match($dom); $css2 = Scraper::css("h1")->extractFirst($dom); $css3 = Scraper::css("a")->extractAll($dom); $css4 = Scraper::css("a")->count($dom);
统计信息
- 总下载量: 165
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-02-24