rajanrx/ php-scrape
一个简单、易用、可扩展的PHP抓取框架
Requires
- php: >=5.6.0
- behat/mink: ~1.6
- behat/mink-browserkit-driver: ~1.2
- behat/mink-goutte-driver: ~1.1
- behat/mink-selenium2-driver: ~1.2
- behat/mink-zombie-driver: ~1.2
- guzzlehttp/cache-subscriber: 0.1.0
- php-curl-class/php-curl-class: 3.5.5
Requires (Dev)
- elliotchance/concise: ~2.0
- jonnyw/php-phantomjs: 3.1.*
- ovr/phpsa: *
- phpmd/phpmd: ~2.4
- phpunit/php-code-coverage: ~3.3.0
- phpunit/phpunit: ~5.2
- squizlabs/php_codesniffer: 3.*
This package is not auto-updated.
Last update: 2024-09-22 08:25:47 UTC
README
一个简单、易用、可扩展的PHP抓取框架
关于PHP Scrape
Php Scrape是一个基于配置优先概念的PHP基本抓取框架。也就是说,一旦实现,应尽可能在配置文件中做出更改,以避免需要代码更新/添加。此外,您可以扩展/自定义此框架到任何级别,或者如果只需使用它们,可以单独使用组件(提取器、爬虫)。
以下是可以使用/未来可以期望的关键点
- 在控制台或浏览器中抓取
- 使用哈希来避免重复抓取(或停止进一步抓取)
- 使用PHP代码生成可编辑的配置文件
- 扩展自己的抓取组件的能力
- 添加用于一般和高级使用说明的完整wiki
- 添加命令行抓取的测试覆盖率(>80%)
- 添加JavaScript抓取的测试覆盖率
- 允许使用代理匿名抓取
- 生成抓取的自动化集成测试以确保数据完整性
为什么还需要另一个git仓库?
抓取数据中最大的问题之一是源代码发生变化,我们必须更新我们的代码库才能使其工作。随着代码库的增大,维护变得更加困难,甚至对于新手来说,寻找更新的位置也很烦人。此外,不同的项目有不同的独特需求(由数据源的种类/复杂性进一步加剧),这些需求可能无法由许多库解决,因为这些库不够通用。因此,为了帮助开发人员解决这些问题,我试图提供一个通用、灵活的解决方案,这可能有助于他们编写易于配置、维护和(扩展/自定义)的抓取项目。
入门
使用PHP Scrape的最简单方法是使用Composer。
composer require rajanrx/php-scrape:^1.1.1
您需要创建配置文件以开始抓取。您可以通过创建配置JSON文件或通过使用php(强烈推荐,因为它更容易维护和扩展)来生成一个。
一旦您有了配置文件,您可以通过编写几行代码开始抓取
<?php use Scraper\Scrape\ConfigurationManager; use Scraper\Scrape\Crawler\Types\GeneralCrawler; use Scraper\Scrape\Extractor\Types\MultipleRowExtractor; require_once(__DIR__ . '/../vendor/autoload.php'); // Grab the crawler $crawler = new GeneralCrawler('https://github.com/trending'); // Get config using configuration manager $path = __DIR__ . "/Data/git-repo.json"; $configurationManager = ConfigurationManager::getInstance($path); // Run extractor (Multiple) as we need to grab multiple rows for Github // trending repos $extractor = new MultipleRowExtractor( $crawler, $configurationManager->getConfiguration() ); $data = $extractor->extract(); // Print retrieved data print_r($data);
将返回类似的结果
Array
(
[0] => Array
(
[repo_name] => ecrmnn / collect.js
[repo_url] => https://github.com/ecrmnn/collect.js
[description] => Convenient and dependency free wrapper for working with arrays and objects
[stars_today] => 493
[hash] => 0e5522aa1ad972b50dc93b8c9f3cc6c8
)
[1] => Array
(
[repo_name] => samdeeplearning / The-Terrible-Deep-Learning-List
[repo_url] => https://github.com/samdeeplearning/The-Terrible-Deep-Learning-List
[description] => 15 working examples to get you started with Deep Learning without learning any of the math.
[stars_today] => 311
[hash] => bd6587020e6072938f441ed22a64375b
)
[2] => Array
(
[repo_name] => tensorflow / models
[repo_url] => https://github.com/tensorflow/models
[description] => Models built with TensorFlow
[stars_today] => 271
[hash] => de60007b8cc8c296918c94e6a525c645
)
...
就是这样简单。详细的文档将很快更新。同时,在文档可用之前,请参阅多行提取器测试以了解如何抓取分页记录。
如果您有任何建议可以使这个代码库变得更好,请告诉我。如果您在抓取项目中遇到困难,我将很高兴提供帮助:)。随时联系我。欢迎感兴趣的贡献者。
合作伙伴
BrowserStack正在支持PHP Scrape,这使我们能够使用他们的服务和基础设施来测试此存储库中的代码。感谢支持开源社区!
许可
此框架是开源软件,许可协议为MIT许可。