我使用 Symfony\Component\HttpClient\HttpClient 来检索页面内容,因为我使用代理。
// Customizing the client
$this->httpClient = HttpClient::create(
[
'proxy' => $connection,
]
);
// I get the content of the page - everything loads normally, in the variable $web string
$web = $this->httpClient->request('GET', 'yandex.ru')->getContent();
强制串连、强制转换,输出相同。 $web = (字符串) $web;
// В $this->client / use simplehtmldom\HtmlWeb;
$this->client->load($web);
// result null
如果我直接传递简单的 html dom - 一切加载正常,这是 Symfony HttpClient 格式不友好。
如果
$this->client
是 simplehtmldom\HtmlWeb
,那么 load 方法需要一个 URL
您可能只想要 HtmlDocument
$document = new \simplehtmldom\HtmlDocument($web);
这就是
simplehtmldom\HtmlWeb
类返回的内容(如果它不返回 null)。
(另外,“web”对于包含 html 源代码的字符串来说是一个奇怪的变量名称)