###前提・実現したいこと
amazonの商品ページにアクセスし、その商品のランキング情報を取得したいです。
gas (Google Apps Script)で書いております。
・常に起動しておけるマシンがないためスプレッドシートで定期実行の体を取りたいため
・スクレイピングした結果は最終的にスプレッドシートで管理するため
サイトにアクセスしたときに弾かれるのをなんとかしたいです。
ユーザーエージェントを設定したのですがダメで、アドバイスいただければ幸いです。
###該当のソースコード
// amazon_ranking.gs function myFunction () { var url = "https://www.amazon.co.jp/dp/B01KZLB6QK/"; var postheader = { "useragent":"Mozilla/5.0", "accept":"gzip", "timeout":20000 } var parameters = { "method":"get", "muteHttpExceptions": true, "headers": postheader } var html = UrlFetchApp.fetch(url, parameters).getContentText('Shift_JIS'); Logger.log(html); }
###エラーレスポンス
<html> <head> <META HTTP-EQUIV="Content-Type" content="text/html; charset=Shift_JIS"> <title> ご迷惑をおかけしています! </title> <style type="text/css"><!-- .serif { font-family: times,serif; font-size: medium; } .sans { font-family: osaka,MS Pゴシック,arial,helvetica,sans-serif; font-size: medium; } .small { font-family: osaka,MS Pゴシック,arial,helvetica,sans-serif; font-size: small; } .h1 { font-family: osaka,MS Pゴシック,arial,helvetica,sans-serif; color: #CC6600; font-size: medium; } .h3color { font-family: osaka,MS Pゴシック,arial,helvetica,sans-serif; color: #CC6600; font-size: small; } .tiny { font-family: osaka,MS Pゴシック,arial,helvetica,sans-serif; font-size: x-small; } --></style> </head> <body bgcolor="#FFFFFF" link="#003399" alink="#FF9933" vlink="#996633" text="#000000"> <!-- 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.jp/ref=rm_5_sv, or our Product Advertising API at https://affiliate.amazon.co.jp/gp/advertising/api/detail/main.html/ref=rm_5_ac for advertising use cases. --> <center> <center> <a href="http://www.amazon.co.jp/exec/obidos/tg/browse/-/489986/ref=cs_503_logo/"> <img src="https://images-fe.ssl-images-amazon.com/images/G/09/other/logo-jp.jpg" width=190 height=60 alt="Amazon.co.jp" border=0></a> <p> <table cellpadding="3" width="90%" bgcolor="#ffffff" border="0" cellspacing="2" align="center"> <tr> <td> <p><b class="h1">ご迷惑をおかけしています!</b></p> <p class="small"> お客様のリクエストの処理中にエラーが発生しました。できるだけ早くこの問題を解決いたします。 </p> <p class="small"> 注文手続きの途中でこのエラーが表示された場合は、注文は確定されていませんので、ご注意ください。 </p> <p class="small"> ご不便をおかけして申し訳ございません。 </p> <p class="small"><a href="http://www.amazon.co.jp/exec/obidos/tg/browse/-/489986/ref=cs_503_link/"><img src="https://images-fe.ssl-images-amazon.com/images/G/09/buttons/continue-shopping.gif" width="125" height="20" align="absmiddle" vspace="2" hspace="6" border="0"></a> Amazon.co.jpホームへ</p> </td> </tr> </table> </body> </html>
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。