【发布时间】:2013-06-16 14:55:02
【问题描述】:
我相信这相当简单。我正在使用下面的函数来检索网站原始 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;
}
网站原始html应该分配给$response,然后返回。
【问题讨论】:
-
请在堆栈溢出时使用空格进行适当的缩进。
-
您发布的内容看起来不错。您确定代码中的其他地方没有问题吗?