PHP 无法在速卖通中使用 file_get_html()

PHP can't use file_get_html() in AliExpress

我一直在尝试在 AliExpress 中使用 file_get_html(),但出现错误。

当我尝试使用以下内容时,一切正常:

        $url = "http://pt.aliexpress.com/br_home.htm";
    $retorno = file_get_html($url);

当我尝试使用它时,一切都崩溃了:

        $url = "http://pt.aliexpress.com/item/2015-Hot-Men-s-Fashion-Casual-Slim-Fit-Suit-Jacket-Solid-Color-High-Quality-Masculine-Blazer/32272100970.html?s=p";
    $retorno = file_get_html($url);

我得到错误:Warning: file_get_contents(http://pt.aliexpress.com/item/2015-Hot-Men-s-Fashion-Casual-Slim-Fit-Suit-Jacket-Solid-Color-High-Quality-Masculine-Blazer/32272100970.html?s=p): failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request in /Users/nando/htdocs/aliex/public/simple_html_dom.php on line 75

我不明白为什么第一个 URL 没问题而第二个我不能用。

如果有人能帮助我,我会很高兴。谢谢。

Crawling/grabbing 来自 URL 的内容在大多数情况下都是不合法的。您应该使用他们提供的 API。这是从 URL

抓取内容的 curl 代码
$url = "Your URL";
$ch = curl_init();
curl_setopt( $ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20041001 Firefox/0.10.1" );
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
curl_setopt( $ch, CURLOPT_ENCODING, "" );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_AUTOREFERER, true );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
echo  $content = curl_exec( $ch );