Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.

Commit 407dec8

Browse files
author
anatolii
committed
Set null as default value to $xpath
updated README.md
1 parent f352cab commit 407dec8

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,23 @@ $ composer require xparse/recursive-pagination
3030
$paginator->addToQueue('http://www.example.com/first/page/to/parse.html');
3131

3232
$allLinks = [];
33-
while ($page = $paginator->getNextPage()) {
33+
while ($page = $paginator->getNextPage()) {
3434
$adsList = $page->attribute("//div[@class='itemdetails']//a/@href")->getItems();
3535
$allLinks = array_values(array_unique(array_merge($allLinks, $adsList)));
3636
}
3737
print_r($allLinks);
38+
3839
```
40+
You can also specify custom xpath string or array to getNextPage() method
41+
42+
```php
43+
while ($page = $paginator->getNextPage("//a[@class='pagination']/@href")) {
44+
$adsList = $page->attribute("//div[@class='itemdetails']//a/@href")->getItems();
45+
$allLinks = array_values(array_unique(array_merge($allLinks, $adsList)));
46+
}
47+
print_r($allLinks);
48+
```
49+
3950

4051
## Testing
4152

src/RecursivePagination.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ class RecursivePagination {
2929

3030
/**
3131
* @param Grabber $grabber
32-
* @param array $xpath
32+
* @param null $xpath
3333
*/
34-
public function __construct(Grabber $grabber, $xpath = []) {
34+
public function __construct(Grabber $grabber, $xpath = null) {
3535
$this->grabber = $grabber;
3636
$this->addXpath($xpath);
3737
}

0 commit comments

Comments
 (0)