php
php curl获取响应,php – curl – 获取html响应正文 -凯发ag旗舰厅登录网址下载
我相信这很简单.我正在使用下面的函数来检索网站原始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
总结
以上是凯发ag旗舰厅登录网址下载为你收集整理的php curl获取响应,php – curl – 获取html响应正文的全部内容,希望文章能够帮你解决所遇到的问题。
如果觉得凯发ag旗舰厅登录网址下载网站内容还不错,欢迎将凯发ag旗舰厅登录网址下载推荐给好友。
- 上一篇:
- 下一篇: