1

我正在尝试使用 php cURL 来获取亚马逊网页,但得到的是 HTTP/1.1 503 Service Temporarily Unavailable。亚马逊阻止 cURL 吗?

http://www.amazon.com/gp/offer-listing/B003B7Q5YY/

<?php

function get_html_content($url) {
    // fake user agent
    $userAgent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.2) Gecko/20070219 Firefox/2.0.0.2';

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch,CURLOPT_COOKIEFILE,'cookies.txt');
    curl_setopt($ch,CURLOPT_COOKIEJAR,'cookies.txt');

    $string = curl_exec($ch);
    curl_close($ch);

    return $string;
}

echo get_html_content("http://www.amazon.com/gp/offer-listing/B003B7Q5YY");

?>
4

1 回答 1

4

我用简单

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $offers_page);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 GTB5');
$html = curl_exec($ch);
curl_close($ch);

但我还有另一个问题。如果您向亚马逊发送大量查询 - 他们开始向您发送 500 页。

于 2013-06-06T12:03:33.047 回答