Alexa 보고서에서 상위 3 개 국가를 가져 오려고하는데을 사용하여 사이트에 액세스 할 수 없습니다 curl
. 하지만 그렇게 할 때 Alexa에서 Amazon에 가입하라는 오류가 표시됩니다. 나는 curl
차단할 수 없다는 것을 알고 있지만 그들은 그것을 한 것 같습니다.
$url="http://www.alexa.com/siteinfo/google.com";
$agent= 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)';
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL,$url);
$result=curl_exec($ch);
echo('<textarea>'.$result.'</textarea>');
작동합니다. 참고 사용하고 싶은 표준 컬 옵션 세트를 사용했습니다. 실제 필요에 따라 자유롭게 조정하십시오. 내가 그렇게 한 이유는 설정하는 동안 $agent
실제로 curl
어떤 식 으로든 전달하지 않기 때문 입니다. 그래서 내 옵션 CURLOPT_USERAGENT
은 몇 가지 다른 것뿐만 아니라 올바르게 설정 됩니다.
$url ="http://www.alexa.com/siteinfo/google.com";
$agent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
$result = curl_exec($ch);
curl_close($ch);
echo('<textarea>'.$result.'</textarea>');
그리고 다음은 Macintosh에서 MAMP를 통해 PHP 5.4를 사용하는 로컬 테스트 환경의 결과입니다.
EDIT: According to the original poster, this script works on one host but not another where he is met with a “403: Forbidden” error. Which points to some kind of blocking happening on the Alexa server. I would recommend debugging by using curl -I
from the command line like this:
curl -I http://www.alexa.com/siteinfo/google.com
And on my local Mac OS X 10.9.4 setup, I get this in response to the request:
HTTP/1.1 200 OK
Content-Type: text/html; charset=UTF-8
Date: Thu, 10 Jul 2014 01:24:51 GMT
Server: Apache
Set-Cookie: rpt=%21; expires=Fri, 11-Jul-2014 02:24:51 GMT; domain=alexa.com
Set-Cookie: lv=1404955491; expires=Fri, 10-Jul-2015 07:24:51 GMT; path=/; domain=alexa.com
Vary: Accept-Encoding
X-Frame-Options: SAMEORIGIN
Connection: keep-alive
The HTTP/1.1 200 OK
means all is good. If you run the same command from the command line & get anything other than that, you can bet you are being blocked. Possibly a block based just on an IP range. Or even blocked via something like ModSecurity which would do heuristic analysis of traffic to catch & block non-standard web requests. Regardless, if you are being blocked on the server side of this, there is not much you can do to unblock yourself.
즉, $agent
내 버전의 스크립트에서 어떻게 올바르게 설정했는지 확인 했지만 그렇지 않습니까? curl
IP를 테스트하는 동안 적절한 사용자 에이전트없이 너무 많은 요청 을 실행 한 것은 테스트에서 일시적으로 차단 될 수 있습니다. 따라서 하루나 이틀을 기다렸다가 다시 시도하지만 내 버전의 스크립트로 적절한 사용자 에이전트가 설정됩니다. 그러면 잘 작동 할 것입니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다