Skip to content

Commit 21e6413

Browse files
Andrey Helldarnicolas-grekas
authored andcommitted
[DomCrawler] Added return of element name in extract() method
1 parent 2dc9211 commit 21e6413

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
4.3.0
5+
-----
6+
7+
* Added return of element name (`_name`) in `extract()` method.
8+
49
4.2.0
510
-----
611

Crawler.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,8 @@ public function extract($attributes)
658658
foreach ($attributes as $attribute) {
659659
if ('_text' === $attribute) {
660660
$elements[] = $node->nodeValue;
661+
} elseif ('_name' === $attribute) {
662+
$elements[] = $node->nodeName;
661663
} else {
662664
$elements[] = $node->getAttribute($attribute);
663665
}

Tests/CrawlerTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,8 @@ public function testExtract()
416416
$this->assertEquals(array(array(), array(), array()), $crawler->extract(array()), '->extract() returns empty arrays if the attribute list is empty');
417417

418418
$this->assertEquals(array(), $this->createTestCrawler()->filterXPath('//ol')->extract('_text'), '->extract() returns an empty array if the node list is empty');
419+
420+
$this->assertEquals(array(array('One', 'li'), array('Two', 'li'), array('Three', 'li')), $crawler->extract(array('_text', '_name')), '->extract() returns an array of extracted data from the node list');
419421
}
420422

421423
public function testFilterXpathComplexQueries()

0 commit comments

Comments
 (0)