我正在使用以下命令来获取 URL 的内容。
$result = curl_exec($ch);
我想解析结果文本。现在我正在做的是$result
在等待固定延迟后解析 的内容,以确保加载整个页面并且页面的全部内容可通过变量$result
.
有没有其他方法可以识别整个页面是否已加载?
Unless you're using curl_multi_exec
, curl_exec
will not return anything until the entire page is loaded, so there is no need to do what you are trying to do. From the manual page:
Returns TRUE on success or FALSE on failure. However, if the CURLOPT_RETURNTRANSFER option is set, it will return the result on success, FALSE on failure.
It won't return anything and your script won't continue until the transfer has finished.
Edit::
It is a bit confusing what is actually happening, but it looks like you are displaying the HTML contents of a page to the browser and that page is redirecting the user to a new page. I'm guessing that this is either a javascript or meta refresh. The only way to prevent this from happening is by parsing through the HTML and removing those elements.
Try adding header('Content-type: text/plain');
to the top of your script and you will see what is actually returned by curl.
你不需要延迟或其他东西。
当您从 curl 返回结果时,它包含整个页面。