【问题标题】:PHP file_get_html is not workingPHP file_get_html 不工作
【发布时间】:2015-06-21 05:02:10
【问题描述】:

我使用了 simple_html_dom 库,但无法仅获取 1 个 URL 的 HTML 内容,但出现 503 错误。检查我下面的代码。

$base = 'http://www.amazon.com/gp/offer-listing/B001F0M4K8/ref=dp_olp_all_mbc/183-8463780-9861412?ie=UTF8&condition=new';

echo $html = file_get_html($base);

错误: 警告:file_get_contents(http://www.amazon.com/gp/offer-listing/B001F0M4K8/ref=dp_olp_all_mbc/183-8463780-9861412?ie=UTF8&condition=new) [function.file-get-contents]:打开流失败:HTTP 请求失败! HTTP/1.1 503 Service Unavailable in D:\xampp\htdocs\webcrawler-amazon\webcrawler-amazon\simple_html_dom.php 第 76 行

我被困在这里所以请帮助我。

【问题讨论】:

  • 可能是他们只允许某些用户代理或其他东西。 503 对我来说将是自定义生成的。一个简单的 file_get_contents 也失败了。因此,您可能必须尝试一些选项。当然,根据请求/获取的类型已经建议。
  • 尝试使用 CURL 加载内容,如下例所示:stackoverflow.com/questions/18667441/…

标签: php file-get-contents simple-html-dom


【解决方案1】:

我认为,服务器只是阻止了您的请求,您将无法使用简单的 HTTP 请求从中获取数据。

您可以尝试使用 curl、代理或两者都使用(有现成的解决方案,例如:AngryCurlRollingCurl

【讨论】:

    【解决方案2】:

    我建议您使用 cURL 执行此操作:http://php.net/manual/en/book.curl.php

    您可以在 PHP 或命令行中使用它。网上有很多例子。

    【讨论】:

      【解决方案3】:

      这是亚马逊的反机器人防御系统。

      返回的页面以以下 HTML 注释开头:

      <!--
              To discuss automated access to Amazon data please contact api-services-support@amazon.com.
              For information about migrating to our APIs refer to our Marketplace APIs at https://developer.amazonservices.com/ref=rm_5_sv, or our Product Advertising API at https://affiliate-program.amazon.com/gp/advertising/api/detail/main.html/ref=rm_5_ac for advertising use cases.
      -->
      

      您需要很好地模仿真实客户使用浏览器的行为,或者向他们询问一种已获批准的自动从他们的系统获取数据的方法。无论如何,使用 API 比报废网页更好(也更容易)。

      【讨论】:

        【解决方案4】:

        我也在做同样的事情,他们正在向您发送以下内容。有时候,你可以过得去。

        Enter the characters you see below
        Sorry, we just need to make sure you're not a robot. For best results, please make sure your browser is accepting cookies.
        Type the characters you see in this image:
         
        
        Try different image 
        Continue shopping 
        
        Conditions of Use Privacy Policy 
        © 1996-2014, Amazon.com, Inc. or its affiliates 
        

        【讨论】:

          猜你喜欢
          • 2014-06-05
          • 2017-07-02
          • 1970-01-01
          • 2015-01-30
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多