xparse/递归分页

此包已被废弃,不再维护。作者建议使用xparse/parser包。

递归分页

0.4.1 2019-05-29 08:42 UTC

README

Latest Version Software License Build Status Coverage Status Quality Score Total Downloads

递归分页允许您递归地解析网站页面。您需要传递一个起始链接并设置下一页表达式(xPath、css等)。

安装

您可以通过Composer安装此包

$ composer require xparse/recursive-pagination

基本用法

尝试查找所有指向github仓库的链接。我们的查询将是 xparse。使用递归分页,我们可以遍历所有分页链接并处理每个结果页面以获取仓库链接。

  use Xparse\Parser\Parser;
  use Xparse\RecursivePagination\RecursivePagination;
  
  # init Parser
  $parser = new Parser();

  # set expression to pagination links
  $paginator = new RecursivePagination($parser, "//*[@class='pagination']//a/@href");
  # set initial page url
  $paginator->addToQueue('https://github.com/search?q=xparse');

  $allLinks = [];
  while (($page = $paginator->getNextPage())) {
    # set expression to fetch repository links
    $adsList = $page->value("//*[@class='repo-list-name']//a/@href")->getItems();
    # merge and remove duplicates
    $allLinks = array_values(array_unique(array_merge($allLinks, $adsList)));
  }
  print_r($allLinks);

测试

$ vendor/bin/phpunit

鸣谢

许可

MIT许可(MIT)。请参阅许可文件以获取更多信息。