Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am trying to import the product titles and review ratings from a listing to a Google Spreadsheet. I have tried the ImportXML fuction using Xpath query but that does not work. So, I tried a code as mentioned below and it worked. I have been able to get the listing data but sometimes it gives me an error instead of displaying the data.

Error:

Request failed for https://www.amazon.co.uk returned code 503. Truncated server response: For information about migrating to ... (use muteHttpExceptions option to examine full response). (line 2).

When I refresh the code or when I add/remove https:// from the url, it works again but when I refresh the sheet, it goes off sometime and displays the error.

Question:

  1. Is there any way to get rid of the error?
  2. While trying to get the Star Rating displayed on the sheet, it uses a Span Data-hook class where the data is stored and I am unable to retrieve it. Is there any way to retrieve the star rating as well?

This is the function that I have created to get the product title and other data:


    function productTitle(url) {   
      var content = UrlFetchApp.fetch(url).getContentText();
      var match = content.match(/<span id="productTitle".*>([^<]*)</span>/);
      return match && match [1] ? match[1] : 'Title not found';
    }

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
169 views
Welcome To Ask or Share your Answers For Others

1 Answer

You are receiving HTTP Status codes of 503, that means the service you are trying to reach is either under maintenance or overloaded.

This is on Amazon's side. You should use the Amazon API instead of the public endpoints for processing this data.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...