2011-01-04 6 views
1

file_get_contents 및 cURL을 사용하여 웹 사이트 콘텐츠를 가져 오려고 시도했지만 Lynx를 사용하여 동일한 사이트를 열려고했으나 콘텐츠를 가져올 수 없었습니다. 내가 406 Acceptable, 내가 사이트를 확인하는 브라우저를 사용하고있는 것 같습니다. 해결 방법이 있습니까?file_get_contents 및 CURL이 (가) 특정 웹 사이트를 열 수 없습니다.

+1

가짜 사용자 에이전트 문자열 : 곱슬. – ceejayoz

답변

2

아마도 사용자 에이전트가 웹 브라우저 일 것으로 기대합니다. 이 쉽게 사용하여 컬을 설정할 수 있습니다 $useragent 당신이 사용자 에이전트에 사용할 문자열입니다

curl_setopt($ch, CURLOPT_USERAGENT, $useragent); 

. 주요 브라우저에 대한 몇 가지 공통점을 가지고 시도해보고 도움이되는지 확인하십시오. 이 페이지는 일부 common user agents을 나열합니다.

0

"실제"브라우저처럼 더 많은 HTTP 헤더를 설정해야 할 수도 있습니다.

curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13'); 
$header = array(
    'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 
    'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7', 
    'Accept-Language: en-us;q=0.8,en;q=0.6' 
); 
curl_setopt($ch, CURLOPT_HTTPHEADER, $header); 
+0

죄송하지만 문제가 해결되지 않았습니다. – mickey

2
//make a call the the webpage to get his handicap 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, "http://www.golfspain.com/portalgolf/HCP/handicap_resul.aspx?sLic=CB00693474"); 
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
curl_setopt($ch, CURLOPT_REFERER, "http://google.com"); 
curl_setopt($ch, CURLOPT_HEADER, TRUE); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); 
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13'); 
$header = array(
    'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 
    'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7', 
    'Accept-Language: en-us;q=0.8,en;q=0.6' 
); 
curl_setopt($ch, CURLOPT_HTTPHEADER, $header); 
$html = curl_exec($ch); 
curl_close($ch); 

$doc = new DOMDocument(); 
$doc->strictErrorChecking = FALSE; 
$doc->loadHTML($html); 
$xml = simplexml_import_dom($doc);