我不明白为什么 CURL 找不到这个 URL。 CURL 引擎只是被带到一个 400 错误页面。
我的代码非常简单,并且可以很好地处理非动态 URL。
我希望它很容易被发现,例如,缺少 CURL 选项。
我试过使用 $url = urlencode($url) 但这也不起作用。
代码如下:
$url = 'http://www.destinations-uk.com/accommodations.php?link=accommodations&country=england&category=Reviews&id=1';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
$r = curl_exec($ch);
$r = explode("\n", $r);
$keys = array();
if(!empty($r)) $keys[] = array_shift($r);
foreach($r as $line){
preg_match('/.+:\s/',$line,$match);
if($match) $keys[substr($match[0],0,-2)] = preg_replace('/.+:\s/','', $line);
}
print_r($keys);
最佳答案
也许,这是服务器端为了防止自动请求而做的事情。
关于php CURL 不适用于动态 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12936940/