PHP无法在AliExpress中使用file_get_html() [英] PHP can't use file_get_html() in AliExpress

查看:228
本文介绍了PHP无法在AliExpress中使用file_get_html()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have been trying to use file_get_html() in AliExpress but I am getting an error.

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

When I try to use the following, everything works:

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

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

When I try to use this, everything collapses:

        $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可以正常运行,而第二个URL无法使用.

I can't figure out why the first URL goes okay and the second I can't use.

如果有人可以帮助我,我会很高兴.谢谢.

If somebody can help me, I will be glad. Thanks.

推荐答案

在大多数情况下,从URL爬行/抓取内容都是不合法的.您应该使用其提供的API.这是卷曲代码,用于从URL抓取内容

Crawling/grabbing content from URL is not legal most of the case. You should use their provided API. Here is the curl code for grabbing content from a URL

$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 );

这篇关于PHP无法在AliExpress中使用file_get_html()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆