gavinggordon / sorcerer
一个易于使用的PHP类,用于抓取网页源代码。
1.0.0
2017-01-14 10:32 UTC
Requires (Dev)
- phpunit/phpunit: 4.0.*
This package is not auto-updated.
Last update: 2024-09-15 01:03:02 UTC
README
描述
一个易于使用的PHP类,用于抓取网页源代码。
使用方法
安装
$ composer require gavinggordon/sorcerer
示例
实例化
include( 'vendor/autoload.php' ); use GGG\Http\Data\Collection\Sorcerer as Sorcerer; $scraper = new Sorcerer();
配置
$url = 'http://www.testurl.com/index.php'; $regexes = [ '/\<a\s?[^\>]+?\>(.+)\<\/a\>/i', '/\<img\s?([^\>]+?)[\s\/]*?\>/i' ]; $savefile = __DIR__ . './testurl-scrapedata.txt'; $scraper->configure( $url, $regexes, $savefile );
运行
如果没有为 "$savefile" 设置文件路径,...
$data = $scraper->scrape(); print_r( $data );
...抓取的数据将被返回。
如果为 "$savefile" 设置了文件路径,...
$scraper->scrape();
...抓取的数据将被保存到您指定的文件中。
问题
如果您有任何问题,请在 https://github.com/gavinggordon/sorcerer/issues 的问题页面上发布您的发现。
许可证
此软件包使用MIT许可证。