Skip to content

Commit 32677c9

Browse files
victor-prdhnicolas-grekas
authored andcommitted
[DomCrawler] Give choice of used parser
1 parent 079ed3b commit 32677c9

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

AbstractBrowser.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ abstract class AbstractBrowser
3737
protected $internalResponse;
3838
protected $response;
3939
protected $crawler;
40+
protected bool $useHtml5Parser = true;
4041
protected $insulated = false;
4142
protected $redirect;
4243
protected $followRedirects = true;
@@ -207,6 +208,18 @@ public function getCrawler(): Crawler
207208
return $this->crawler;
208209
}
209210

211+
/**
212+
* Sets whether parsing should be done using "masterminds/html5".
213+
*
214+
* @return $this
215+
*/
216+
public function useHtml5Parser(bool $useHtml5Parser): static
217+
{
218+
$this->useHtml5Parser = $useHtml5Parser;
219+
220+
return $this;
221+
}
222+
210223
/**
211224
* Returns the current BrowserKit Response instance.
212225
*/
@@ -497,7 +510,7 @@ protected function createCrawlerFromContent(string $uri, string $content, string
497510
return null;
498511
}
499512

500-
$crawler = new Crawler(null, $uri);
513+
$crawler = new Crawler(null, $uri, null, $this->useHtml5Parser);
501514
$crawler->addContent($content, $type);
502515

503516
return $crawler;

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+
6.3
5+
---
6+
7+
* Add `AbstractBrowser::useHtml5Parser()`
8+
49
6.1
510
---
611

0 commit comments

Comments
 (0)