【问题标题】:Fetch Amazon Customer Review Contents by Link. How?通过链接获取亚马逊客户评论内容。如何?
【发布时间】:2017-01-26 15:54:13
【问题描述】:

目前,我通过评论链接获取亚马逊客户评论的方式是使用

PHP Simple HTML DOM Parser.

通过提供评论链接,我可以获取评论内容,例如 标题、评分、评论、描述、图片、视频、作者等。

如果我知道每个内容的css selector,这一切都是可能的。

向您展示我是如何做到的:

$url = 'REVIEW_URL_HERE';
$html = file_get_html($url,false); //see PHP Simple HTML DOM Parser
$testSelector='#SAMPLE-SELECTOR';
$content = $html->find($testSelector, 0)->plaintext;
//echo $content; //error-> seems selector is not present.
echo $html; // i expect the review link page will be loaded. but the loaded page is different

输出意外。因为我echo $html,我期待评论页面。但显示了不同的页面:

我用来获取评论内容的方法似乎不再可行。新方法的任何想法? 我发现 AWS 关于获取评论...但 AFAIK 它不返回评论内容..它只返回评论链接..

【问题讨论】:

    标签: php amazon simple-html-dom review amazon-product-api


    【解决方案1】:

    当然可以,但您必须是 Amazon 开发人员并使用他们的 API。查看文档here

    【讨论】:

    • 感谢 Eric 的回复,正如我所提到的,它只会返回 iframe src 链接。并且由于跨域问题..我无法获取 iframe 中的内容...除非你知道怎么做?
    • 您可以使用 file_get_contents 在 PHP 中读取 iframe 的内容,甚至可以在 CURL 中读取。
    • hmmmm 好吧..我会检查一下,一旦得到结果就会回复你。 :) 谢谢
    【解决方案2】:

    您看到此消息是因为您可能多次调用 amazon apis。在这种情况下,亚马逊正在阻止 IP 地址。更改您的互联网提供商,它应该可以开始工作了。

    【讨论】:

      【解决方案3】:

      也许您需要使用 php 和 PhantomJs 以及简单的 Javascript。 并且不要忘记:使用代理

      有些是这样的:

       <?php
       $html = exec("phantomjs --proxy=127.0.0.1:80 --proxy-auth=root:master 
        test.js http://httpbin.org/ip");
       ?>
      

      test.js

      var args = require('system').args;
      var webPage = require('webpage');
      var address = args[1];
      var page = webPage.create();
      var fs = require('fs');
      var pageResponses = {};
      
      page.settings.userAgent = 'Mozilla/5.0 (Windows NT 10.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36';
      page.settings.javascriptEnabled = true;
      page.settings.loadImages = false;
      phantom.cookiesEnabled = false;
      phantom.javascriptEnabled = true;
      page.settings.resourceTimeout = 20000;
      page.customHeaders = { // use correct header
          "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
          "Accept-Language": "en-US,en;q=0.5",
          "Connection": "keep-alive",
      };
      page.viewportSize = { width: 1024, height: 768 };
      
      try {
          page.open(address, function (status) {
             console.log(page.content);
             window.setTimeout(function () {
                phantom.exit();
            }, Math.random()*500 + 1500);
         });
      } catch(e) {
          phantom.exit(1);
      }
      

      【讨论】:

        猜你喜欢
        • 2017-07-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-07-22
        • 2018-07-21
        • 2012-03-24
        • 1970-01-01
        • 2020-07-07
        相关资源
        最近更新 更多