/** * @inheritdoc * @throws \InvalidArgumentException */ public function create(ResponseInterface $response, $affectedUrl = null) { $html = $response->getBody(); $html = StringHelper::safeEncodeStr((string) $html); $contentType = $response->getHeaderLine('content-type'); $html = HtmlEncodingConverter::convertToUtf($html, $contentType); $page = new ElementFinder((string) $html); if ($affectedUrl !== null) { LinkConverter::convertUrlsToAbsolute($page, $affectedUrl); } return $page; }
/** * @param $data * @return $this */ protected function setData($data) { $internalErrors = libxml_use_internal_errors(true); $disableEntities = libxml_disable_entity_loader(true); if ($this->type == static::DOCUMENT_HTML) { $data = StringHelper::safeEncodeStr($data); $data = mb_convert_encoding($data, 'HTML-ENTITIES', "UTF-8"); $this->dom->loadHTML($data); } else { $this->dom->loadXML($data, $this->options); } libxml_use_internal_errors($internalErrors); libxml_disable_entity_loader($disableEntities); unset($this->xpath); $this->xpath = new \DomXPath($this->dom); return $this; }