php curl获取响应,php – cUrl – 获取html响应正文
我相信這很簡單.我正在使用下面的函數來檢索網站原始HTML
為了解析它.在我的測試中,我決定在stackoverflow.com上運行我的代碼
Chrome沒有獲取html響應,而是打印出實際網站,而不是將html分配給它真實的.我錯過了什么?
function get_site_html($site_url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 4);
curl_setopt($ch, CURLOPT_FORBID_REUSE, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_URL, $site_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
global $base_url;
$base_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
$http_response_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close ($ch);
return $response;
}
The site raw html should be assigned to $response, and then return it.
解決方法:
你的代碼有效.嘗試echo htmlentities($response);您將獲得您正在卷曲的網站的原始html.
標簽:php,curl
來源: https://codeday.me/bug/20191008/1871633.html
總結
以上是生活随笔為你收集整理的php curl获取响应,php – cUrl – 获取html响应正文的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: redis php扩展 linux,li
- 下一篇: php array_only,php可以