{"id":852,"date":"2010-11-24T17:56:32","date_gmt":"2010-11-24T08:56:32","guid":{"rendered":"http:\/\/peta.okechan.net\/blog\/?p=852"},"modified":"2010-11-24T17:56:32","modified_gmt":"2010-11-24T08:56:32","slug":"amazon%e3%81%ae%e5%95%86%e5%93%81%e5%80%8b%e5%88%a5%e3%83%9a%e3%83%bc%e3%82%b8%e3%81%aeurl%e3%81%8b%e3%82%89asin%e3%82%92%e5%8f%96%e5%be%97%e3%81%99%e3%82%8b","status":"publish","type":"post","link":"https:\/\/peta.okechan.net\/blog\/archives\/852","title":{"rendered":"Amazon\u306e\u5546\u54c1\u500b\u5225\u30da\u30fc\u30b8\u306eURL\u304b\u3089ASIN\u3092\u53d6\u5f97\u3059\u308b"},"content":{"rendered":"<p>\u98a8\u90aa\u3092\u5f15\u3044\u3066\u3057\u307e\u3044\u307e\u3057\u305f\u3002\u9f3b\u98a8\u90aa\u3063\u3066\u3084\u3064\u3067\u3059\u3002\u71b1\u306f\u5927\u3057\u305f\u3053\u3068\u306a\u3044\u3067\u3059\u304c\u982d\u75db\u304c\u8f9b\u3044\u3067\u3059\u3002<\/p>\n<p>\u81ea\u52d5\u3067\u30cd\u30c3\u30c8\u3092\u30af\u30ed\u30fc\u30eb\u3057Amazon\u30a2\u30bd\u30b7\u30a8\u30a4\u30c8\u30ea\u30f3\u30af\u3092\u53ce\u96c6\u3059\u308b\u30ed\u30dc\u30c3\u30c8\u3092\u4f5c\u3063\u3066\u3001\u3044\u308f\u3086\u308b\u8a71\u984c\u306e\u5546\u54c1\u306a\u3093\u3066\u306e\u3092\u898b\u308c\u308b\u3068\u9762\u767d\u305d\u3046\u3060\u306a\u3068\u5bdd\u3066\u3044\u308b\u3068\u304d\u306b\u601d\u3044\u3064\u304d\u307e\u3057\u3066\u3001\u8a66\u3057\u306b\u8272\u3005\u5b9f\u9a13\u3057\u3066\u3044\u308b\u3068\u3053\u308d\u3067\u3059\u3002<\/p>\n<p>\u30b5\u30af\u3063\u3068\u30af\u30ed\u30fc\u30e9\u3092\u4f5c\u3063\u3066\u3001\u3068\u308a\u3042\u3048\u305a10\u4e07URL\u307b\u3069\u96c6\u3081\u3066\u307f\u307e\u3057\u305f\u304c\u3001\u81ea\u4f5c\u306eASIN\u62bd\u51fa\u30b3\u30fc\u30c9\u306e\u7cbe\u5ea6\u304c\u5fae\u5999\u306b\u4f4e\u3044\u3053\u3068\u306b\u6c17\u304c\u4ed8\u304d\u307e\u3057\u305f\u3002<br \/>\n\u30cd\u30c3\u30c8\u4e0a\u3067ASIN\u62bd\u51fa\u306e\u6b63\u898f\u8868\u73fe\u306a\u3093\u304b\u3092\u691c\u7d22\u3057\u3066\u307f\u307e\u3057\u305f\u304c\u3001\u306a\u304b\u306a\u304b\u6c7a\u5b9a\u7248\uff01\u3068\u3044\u3063\u305f\u96f0\u56f2\u6c17\u306e\u3042\u308b\u8a18\u4e8b\u304c\u306a\u304f\u3002\u3068\u3044\u3046\u304b\u5168\u4f53\u7684\u306b\u60c5\u5831\u304c\u53e4\u3044\u3002<br \/>\n\u6b63\u898f\u8868\u73fe\u3067\u4e00\u767a\u3068\u306f\u3044\u304d\u307e\u305b\u3093\u304c\u3001\u305d\u306e\u306a\u304b\u3067\u3082\u6bd4\u8f03\u7684\u65b0\u3057\u304f\uff08\u305d\u308c\u3067\u3082\u53e4\u3081\uff09\u3001\u304d\u3061\u3093\u3068\u66f8\u304b\u308c\u3066\u308b\u3063\u307d\u3044\u30a6\u30ce\u30a6\u30e9\u30dc\u306e<a href=\"http:\/\/labs.unoh.net\/2008\/03\/amazonurlasin.html\" target=\"_blank\">Amazon\u306e\u5546\u54c1\u500b\u5225\u30da\u30fc\u30b8\u306eURL\u304b\u3089ASIN\u3092\u53d6\u5f97\u3059\u308b<\/a>\u3068\u3044\u3046\u8a18\u4e8b\u3092\u53c2\u8003\u306b\u3001JavaScript\u3067\u66f8\u304b\u308c\u305f\u30b5\u30f3\u30d7\u30eb\u3092Python\u306b\u79fb\u690d\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\ndef get_asin_from_url(url):\r\n\t'''\r\n\turl\u304b\u3089asin\u3092\u62bd\u51fa\r\n\t'''\r\n\tamazon_r = re.compile(r'^https?:\/\/(?:www\\.)?amazon\\.(?:com|ca|co\\.uk|de|co\\.jp|jp|fr|cn)\/(.+)$')\r\n\tamazon = amazon_r.match(url)\r\n\tif not amazon:\r\n\t\treturn None\r\n\t\r\n\tpath = amazon.group(1)\r\n\tpaths = path.split('\/')\r\n\tif paths&#x5B;0].lower() == 'exec':\r\n\t\tpaths = paths&#x5B;1:]\r\n\tif len(paths) &lt;= 1 or paths&#x5B;1] == '':\r\n\t\treturn None\r\n\t\r\n\tif paths&#x5B;0] in &#x5B;'OBIDOS', 'obidos', 'o']:\r\n\t\tif paths&#x5B;1].lower() == 'asin' and len(paths) &gt;= 3 and paths&#x5B;2] != '':\r\n\t\t\treturn paths&#x5B;2]\r\n\t\telse:\r\n\t\t\tisbn_r = re.compile(r'^isbn(?:=|%3d)(.+)$')\r\n\t\t\tisbn = isbn_r.match(paths&#x5B;1])\r\n\t\t\tif isbn:\r\n\t\t\t\treturn isbn.group(1)\r\n\t\t\telif paths&#x5B;1].lower() == 'tg' \\\r\n\t\t\tand len(paths) &gt;= 5 \\\r\n\t\t\tand paths&#x5B;2].lower() == 'detail' \\\r\n\t\t\tand paths&#x5B;3] == '-':\r\n\t\t\t\tis_asin_r = re.compile(r'^&#x5B;0-9a-zA-Z]{10}$')\r\n\t\t\t\tis_asin = is_asin_r.match(paths&#x5B;4])\r\n\t\t\t\tif is_asin:\r\n\t\t\t\t\treturn paths&#x5B;4]\r\n\t\t\t\telif len(paths) &gt;=6 and paths&#x5B;5] != '':\r\n\t\t\t\t\treturn paths&#x5B;5]\r\n\telif paths&#x5B;0] == 'gp':\r\n\t\tgp_r = re.compile(r'^gp\/product(?:\/product-description)?\/(&#x5B;0-9a-zA-Z]{10})')\r\n\t\tgp = gp_r.match(path)\r\n\t\tif gp:\r\n\t\t\treturn gp.group(1)\r\n\telse:\r\n\t\tpd_r = re.compile(r'\/?dp(?:\/product-description)?\/(&#x5B;0-9a-zA-Z]{10})')\r\n\t\tpd = pd_r.match(path)\r\n\t\tif pd:\r\n\t\t\treturn pd.group(1)\r\n\treturn None\r\n<\/pre>\n<p>\u898b\u3066\u306e\u901a\u308a\u3001\u5143\u306eJavaScript\u306e\u30b3\u30fc\u30c9\u3092\u305d\u306e\u307e\u307e\u99ac\u9e7f\u6b63\u76f4\u306bPython\u306b\u66f8\u304d\u63db\u3048\u305f\u611f\u3058\u306b\u306a\u3063\u3066\u307e\u3059\u3002<br \/>\n\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u7684\u306b\u30ed\u30d0\u30b9\u30c8\u3055\u306f\u3042\u307e\u308a\u306a\u3055\u3052\u306a\u96f0\u56f2\u6c17\u3067\u3059\u304c\u3001\u8aa4\u8a8d\u8b58\u304c\u306a\u304f\u306a\u3063\u305f\u306e\u3067\u3053\u308c\u3067\u3088\u3057\u3068\u3057\u307e\u3059\u3002<\/p>\n<p>\u3068\u308a\u3042\u3048\u305a\u88ab\u53c2\u7167\u56de\u6570\u306e\u964d\u9806\u306bAmazon\u306e\u8a71\u984c\u306e\u5546\u54c1\u3092\u534a\u624b\u4f5c\u696d\u3067\u96c6\u8a08\u3057\u3066\u307f\u307e\u3057\u305f\u304c\u3001\u307f\u3054\u3068\u306b\u30a2\u30cb\u30e1\u95a2\u9023\u306e\u5546\u54c1\u3070\u304b\u308a\u3067\u3057\u305f\u3002<br \/>\n\u500b\u4eba\u7684\u306b\u306fPC\u95a2\u9023\u5546\u54c1\u304c\u898b\u308c\u308b\u3068\u3088\u304b\u3063\u305f\u3093\u3067\u3059\u304c\u3002<br \/>\n\u30af\u30ed\u30fc\u30eb\u958b\u59cb\u30da\u30fc\u30b8\u306e\u9078\u5b9a\u3092\u8aa4\u3063\u305f\u304b\u306aw<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u98a8\u90aa\u3092\u5f15\u3044\u3066\u3057\u307e\u3044\u307e\u3057\u305f\u3002\u9f3b\u98a8\u90aa\u3063\u3066\u3084\u3064\u3067\u3059\u3002\u71b1\u306f\u5927\u3057\u305f\u3053\u3068\u306a\u3044\u3067\u3059\u304c\u982d\u75db\u304c\u8f9b\u3044\u3067\u3059\u3002<\/p>\n<p>\u81ea\u52d5\u3067\u30cd\u30c3\u30c8\u3092\u30af\u30ed\u30fc\u30eb\u3057Amazon\u30a2\u30bd\u30b7\u30a8\u30a4\u30c8\u30ea\u30f3\u30af\u3092\u53ce\u96c6\u3059\u308b\u30ed\u30dc\u30c3\u30c8\u3092\u4f5c\u3063\u3066\u3001\u3044\u308f\u3086\u308b\u8a71\u984c\u306e\u5546\u54c1\u306a\u3093\u3066\u306e\u3092\u898b\u308c\u308b\u3068\u9762\u767d\u305d\u3046\u3060\u306a\u3068\u5bdd\u3066\u3044\u308b\u3068\u304d\u306b\u601d\u3044\u3064\u304d\u307e\u3057\u3066\u3001\u8a66\u3057\u306b\u8272\u3005\u5b9f\u9a13\u3057\u3066\u3044\u308b\u3068\u3053\u308d\u3067\u3059\u3002<\/p>\n<p>\u30b5\u30af\u3063\u3068\u30af\u30ed\u30fc\u30e9\u3092\u4f5c\u3063\u3066\u3001\u3068\u308a\u3042\u3048\u305a10\u4e07URL\u307b\u3069\u96c6\u3081\u3066\u307f\u307e\u3057\u305f\u304c\u3001\u81ea\u4f5c\u306eASIN\u62bd\u51fa\u30b3\u30fc\u30c9\u306e\u7cbe\u5ea6\u304c\u5fae\u5999\u306b\u4f4e\u3044\u3053\u3068\u306b\u6c17\u304c\u4ed8\u304d\u307e\u3057\u305f\u3002<br \/>\n\u30cd\u30c3\u30c8\u4e0a\u3067ASIN\u62bd\u51fa\u306e\u6b63\u898f\u8868\u73fe\u306a\u3093\u304b\u3092\u691c\u7d22\u3057\u3066\u307f\u307e\u3057\u305f\u304c\u3001\u306a\u304b\u306a\u304b\u6c7a\u5b9a\u7248\uff01\u3068\u3044\u3063\u305f\u96f0\u56f2\u6c17\u306e\u3042\u308b\u8a18\u4e8b\u304c\u306a\u304f\u3002\u3068\u3044\u3046\u304b\u5168\u4f53\u7684\u306b\u60c5\u5831\u304c\u53e4\u3044\u3002<br \/>\n\u6b63\u898f\u8868\u73fe\u3067\u4e00\u767a\u3068\u306f\u3044\u304d\u307e\u305b\u3093\u304c\u3001\u305d\u306e\u306a\u304b\u3067\u3082\u6bd4\u8f03\u7684\u65b0\u3057\u304f\uff08\u305d\u308c\u3067\u3082\u53e4\u3081\uff09\u3001\u304d\u3061\u3093\u3068\u66f8\u304b\u308c\u3066\u308b\u3063\u307d\u3044\u30a6\u30ce\u30a6\u30e9\u30dc\u306e<a href=\"http:\/\/labs.unoh.net\/2008\/03\/amazonurlasin.html\" target=\"_blank\">Amazon\u306e\u5546\u54c1\u500b\u5225\u30da\u30fc\u30b8\u306eURL\u304b\u3089ASIN\u3092\u53d6\u5f97\u3059\u308b<\/a>\u3068\u3044\u3046\u8a18\u4e8b\u3092\u53c2\u8003\u306b\u3001JavaScript\u3067\u66f8\u304b\u308c\u305f\u30b5\u30f3\u30d7\u30eb\u3092Python\u306b\u79fb\u690d\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\ndef get_asin_from_url(url):\r\n\t'''\r\n\turl\u304b\u3089asin\u3092\u62bd\u51fa\r\n\t'''\r\n\tamazon_r = re.compile(r'^https?:\/\/(?:www\\.)?amazon\\.(?:com|ca|co\\.uk|de|co\\.jp|jp|fr|cn)\/(.+)$')\r\n\tamazon = amazon_r.match(url)\r\n\tif not amazon:\r\n\t\treturn None\r\n\t\r\n\tpath = amazon.group(1)\r\n\tpaths = path.split('\/')\r\n\tif paths&#x5B;0].lower() == 'exec':\r\n\t\tpaths = paths&#x5B;1:]\r\n\tif len(paths) &lt;= 1 or paths&#x5B;1] == '':\r\n\t\treturn None\r\n\t\r\n\tif paths&#x5B;0] in &#x5B;'OBIDOS', 'obidos', 'o']:\r\n\t\tif paths&#x5B;1].lower() == 'asin' and len(paths) &gt;= 3 and paths&#x5B;2] != '':\r\n\t\t\treturn paths&#x5B;2]\r\n\t\telse:\r\n\t\t\tisbn_r = re.compile(r'^isbn(?:=|%3d)(.+)$')\r\n\t\t\tisbn = isbn_r.match(paths&#x5B;1])\r\n\t\t\tif isbn:\r\n\t\t\t\treturn isbn.group(1)\r\n\t\t\telif paths&#x5B;1].lower() == 'tg' \\\r\n\t\t\tand len(paths) &gt;= 5 \\\r\n\t\t\tand paths&#x5B;2].lower() == 'detail' \\\r\n\t\t\tand paths&#x5B;3] == '-':\r\n\t\t\t\tis_asin_r = re.compile(r'^&#x5B;0-9a-zA-Z]{10}$')\r\n\t\t\t\tis_asin = is_asin_r.match(paths&#x5B;4])\r\n\t\t\t\tif is_asin:\r\n\t\t\t\t\treturn paths&#x5B;4]\r\n\t\t\t\telif len(paths) &gt;=6 and paths&#x5B;5] != '':\r\n\t\t\t\t\treturn paths&#x5B;5]\r\n\telif paths&#x5B;0] == 'gp':\r\n\t\tgp_r = re.compile(r'^gp\/product(?:\/product-description)?\/(&#x5B;0-9a-zA-Z]{10})')\r\n\t\tgp = gp_r.match(path)\r\n\t\tif gp:\r\n\t\t\treturn gp.group(1)\r\n\telse:\r\n\t\tpd_r = re.compile(r'\/?dp(?:\/product-description)?\/(&#x5B;0-9a-zA-Z]{10})')\r\n\t\tpd = pd_r.match(path)\r\n\t\tif pd:\r\n\t\t\treturn pd.group(1)\r\n\treturn None\r\n<\/pre>\n<p>\u898b\u3066\u306e\u901a\u308a\u3001\u5143\u306eJavaScript\u306e\u30b3\u30fc\u30c9\u3092\u305d\u306e\u307e\u307e\u99ac\u9e7f\u6b63\u76f4\u306bPython\u306b\u66f8\u304d\u63db\u3048\u305f\u611f\u3058\u306b\u306a\u3063\u3066\u307e\u3059\u3002<br \/>\n\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u7684\u306b\u30ed\u30d0\u30b9\u30c8\u3055\u306f\u3042\u307e\u308a\u306a\u3055\u3052\u306a\u96f0\u56f2\u6c17\u3067\u3059\u304c\u3001\u8aa4\u8a8d\u8b58\u304c\u306a\u304f\u306a\u3063\u305f\u306e\u3067\u3053\u308c\u3067\u3088\u3057\u3068\u3057\u307e\u3059\u3002<\/p>\n<p>\u3068\u308a\u3042\u3048\u305a\u88ab\u53c2\u7167\u56de\u6570\u306e\u964d\u9806\u306bAmazon\u306e\u8a71\u984c\u306e\u5546\u54c1\u3092\u534a\u624b\u4f5c\u696d\u3067\u96c6\u8a08\u3057\u3066\u307f\u307e\u3057\u305f\u304c\u3001\u307f\u3054\u3068\u306b\u30a2\u30cb\u30e1\u95a2\u9023\u306e\u5546\u54c1\u3070\u304b\u308a\u3067\u3057\u305f\u3002<br \/>\n\u500b\u4eba\u7684\u306b\u306fPC\u95a2\u9023\u5546\u54c1\u304c\u898b\u308c\u308b\u3068\u3088\u304b\u3063\u305f\u3093\u3067\u3059\u304c\u3002<br \/>\n\u30af\u30ed\u30fc\u30eb\u958b\u59cb\u30da\u30fc\u30b8\u306e\u9078\u5b9a\u3092\u8aa4\u3063\u305f\u304b\u306aw<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32],"tags":[360,60],"class_list":["post-852","post","type-post","status-publish","format-standard","hentry","category-tech","tag-amazon","tag-python"],"_links":{"self":[{"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/posts\/852","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/comments?post=852"}],"version-history":[{"count":0,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/posts\/852\/revisions"}],"wp:attachment":[{"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/media?parent=852"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/categories?post=852"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/tags?post=852"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}