0
411.com의 텍스트를 가져올 수 있도록이 컬 코드가 있습니다. 내 localhost에서 wamp를 사용하여 이것을 테스트하면 코드가 완벽하게 작동하지만 온라인으로 테스트 할 때 오류 연결 시간이 초과됩니다.온라인 상태 일 때 cURL 시간이 초과되었지만 localhost가 아닌 경우
내 웹 사이트는 SSL을 사용합니다. 그게 중요한지 확실하지 않습니다.
<?php
//$url = "http://www.411.com/phone/1-310-402-9829";
$url = "www.411.com";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2227.1 Safari/537.36');
$output = curl_exec($ch);
if(curl_errno($ch))
{
echo 'error:' . curl_error($ch);
}
curl_close($ch);
function extract_unit($string, $start, $end)
{
$pos = stripos($string, $start);
$str = substr($string, $pos);
$str_two = substr($str, strlen($start));
$second_pos = stripos($str_two, $end);
$str_three = substr($str_two, 0, $second_pos);
$unit = trim($str_three); // remove whitespaces
return $unit;
}
$unit = extract_unit($output, '<span class="subtitle block pull-left">', 'in');
// Outputs: acronym
echo $unit;
?>
귀하의 호스팅 서비스에는 연결을 차단하는 방화벽이있을 수 있습니다. – Barmar
@Barmar 방금 호스팅 서비스에 연락하여 411.com이 IP를 차단하고 있다고 나에게 알려주었습니다. 이것에 대해 내가 뭘 할 수 있을까? 프록시를 사용 하시겠습니까? – DanMossa
그래, 그게 효과가있을거야. – Barmar