{"id":294,"date":"2017-11-13T13:42:11","date_gmt":"2017-11-13T04:42:11","guid":{"rendered":"https:\/\/jidouka.work\/?p=294"},"modified":"2017-11-13T13:42:32","modified_gmt":"2017-11-13T04:42:32","slug":"gas-web%e3%82%b9%e3%82%af%e3%83%ac%e3%82%a4%e3%83%94%e3%83%b3%e3%82%b0%e3%81%a7%e4%be%a1%e6%a0%bccom%e3%81%8b%e3%82%89%e6%9c%80%e5%ae%89%e5%80%a4%e3%82%92%e5%8f%96%e5%be%97%e3%81%99%e3%82%8b","status":"publish","type":"post","link":"https:\/\/jidouka.work\/?p=294","title":{"rendered":"[GAS] Web\u30b9\u30af\u30ec\u30a4\u30d4\u30f3\u30b0\u3067\u4fa1\u683ccom\u304b\u3089\u6700\u5b89\u5024\u3092\u53d6\u5f97\u3059\u308b"},"content":{"rendered":"<p>\u5546\u54c1\u306e\u4fa1\u683c\u60c5\u5831\u3092\u7c21\u5358\u306b\u53d6\u5f97\u3057\u305f\u3044\u6642\u3068\u304b\u3042\u308a\u307e\u3059\u306d\u3002\u3055\u3089\u306b\u30ea\u30b9\u30c8\u306b\u3057\u3066\u4e00\u6c17\u306b\u53d6\u5f97\u3057\u305f\u3044\u3002\u53d6\u5f97\u3057\u305f\u4fa1\u683c\u60c5\u5831\u3092\u4f7f\u3063\u3066\u4f55\u304b\u3092\u3057\u305f\u3044\u3002<br \/>\n\u305d\u3046\u3044\u3063\u305f\u6642\u306b\u306f\u30b9\u30af\u30ea\u30d7\u30c8\u3067\u4fa1\u683c\u60c5\u5831\u3092\u4e00\u62ec\u3057\u3066\u7d20\u65e9\u304f\u53d6\u5f97\u3067\u304d\u308c\u3070\u697d\u3067\u3059\u3002<\/p>\n<p>\u4eca\u56de\u306fGAS(Google Apps Script)\u3067\u6307\u5b9a\u3057\u305fURL\u306e\u5546\u54c1\u540d\u3001\u4fa1\u683c\u60c5\u5831\u3092\u53d6\u5f97\u3059\u308b\u30b9\u30af\u30ea\u30d7\u30c8\u3067\u3059\u3002<\/p>\n<h2>\u4fa1\u683ccom\u306eHTML\u3092\u78ba\u8a8d<\/h2>\n<h3>\u5546\u54c1\u540d<\/h3>\n<p>\u4fa1\u683ccom\u306e\u5546\u54c1\u540d\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306bh2\u30bf\u30b0\u3067\u56f2\u307e\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<p><strong>&lt;h2 itemprop=&#8221;name&#8221;&gt;iPhone X 256GB SIM\u30d5\u30ea\u30fc&lt;\/h2&gt;<\/strong><\/p>\n<p>\u305d\u306e\u305f\u3081h2\u30bf\u30b0\u3067\u56f2\u307e\u308c\u3066\u3044\u308b\u90e8\u5206\u306e\u6587\u5b57\u5217\u3092\u53d6\u5f97\u3059\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002<br \/>\n\u3057\u304b\u3057\u6b8b\u5ff5\u306a\u304c\u3089GAS\u3067\u306f\u6307\u5b9a\u3057\u305f\u30bf\u30b0\u3092\u53d6\u5f97\u3059\u308b<em>getElementsByTagName<\/em>\u304c\u4f7f\u3048\u307e\u305b\u3093\u3002<br \/>\n\u305d\u306e\u305f\u3081\u30bf\u30b0\u304b\u3089\u6587\u5b57\u5217\u3092\u53d6\u5f97\u3059\u308b\u95a2\u6570\u3092\u4f5c\u3063\u3066\u5bfe\u5fdc\u3057\u307e\u3059\u3002<\/p>\n<p>\u53c2\u8003<br \/>\nGAS\u3067\u306egetElementsByTagName\u3063\u307d\u3044\u3082\u306e &#8211; \u30d4\u30ea\u8f9b\u7684\u5099\u5fd8\u9332<br \/>\n<a href=\"https:\/\/sites.google.com\/site\/lifeslash7830\/home\/gas\/gasdenogetelementsbytagnameppoimono\">https:\/\/sites.google.com\/site\/lifeslash7830\/home\/gas\/gasdenogetelementsbytagnameppoimono<\/a><\/p>\n<h3>\u6700\u5b89\u5024\u306e\u53d6\u5f97<\/h3>\n<p>\u4fa1\u683ccom\u306e\u6700\u5b89\u5024\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306bspan\u30bf\u30b0\u3067\u56f2\u307e\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<p><strong>&lt;div&gt;&lt;span id=&#8221;minPrice&#8221;&gt;\u6700\u5b89\u4fa1\u683c\uff08\u7a0e\u8fbc\uff09\uff1a&lt;a href=&#8221;http:\/\/kakaku.com\/shop\/1989\/?pdid=K0000995743&#038;lid=shop_itemview_saiyasukakaku&#8221;&gt;&lt;span&gt;&yen;140,184\uff5e&lt;\/span&gt;&lt;\/a&gt;&lt;\/span&gt;<\/strong><\/p>\n<p>\u6700\u5b89\u4fa1\u683c\u306f<em>&lt;span&gt;&yen;140,184<\/em>\u3067\u62bd\u51fa\u3057\u305f\u6642\u306b\u4e00\u756a\u6700\u521d\u306b\u304f\u308b\u305f\u3081\u3001\u305d\u308c\u3092\u4f7f\u7528\u3057\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<h2>\u30b3\u30fc\u30c9<\/h2>\n<figure class=\"jd-code\"><button type=\"button\" class=\"jd-code-copy\">\u30b3\u30d4\u30fc<\/button><pre><code class=\"language-javascript\">function getPrice() {\r\n  \r\n  \/\/\u73fe\u5728\u306e\u30b9\u30d7\u30ec\u30c3\u30c9\u30b7\u30fc\u30c8\u3092\u53d6\u5f97\r\n  var aBook = SpreadsheetApp.getActiveSpreadsheet();\r\n  \r\n  \/\/&quot;\u4fa1\u683c\u8868&quot;\u30b7\u30fc\u30c8\u3092\u53d6\u5f97\r\n  var aSheet = aBook.getSheetByName(&quot;\u4fa1\u683c\u8868&quot;);\r\n  \r\n  \/\/&quot;\u4fa1\u683c\u8868&quot;\u30b7\u30fc\u30c8\u306e\u6700\u7d42\u884c\u3092\u53d6\u5f97\r\n  var lastRow = aSheet.getDataRange().getLastRow();\r\n\r\n  \/\/2\u884c\u76ee\u304b\u3089\u6700\u7d42\u884c\u307e\u3067\u30eb\u30fc\u30d7\r\n  for (var i = 2; i &lt;= lastRow; i++) {\r\n    \r\n    \/\/1\u5217\u76ee\u306ei\u884c\u306eURL\u3092\u53d6\u5f97\r\n    var url = aSheet.getRange(i, 1).getValue();\r\n    \r\n    \/\/URL\u30da\u30fc\u30b8\u3092\u53d6\u5f97\r\n    var response = UrlFetchApp.fetch(url);\r\n    \r\n    \/\/HTML\u6587\u3092\u53d6\u5f97\r\n    var html = response.getContentText(&#039;shift_jis&#039;);\r\n    \r\n    \/\/h2\u30bf\u30b0\u304b\u3089\u5546\u54c1\u540d\u3092\u53d6\u5f97\r\n    var itemName = getContentOfTagName(html, &#039;h2&#039;);\r\n        \r\n    \/\/\u6b63\u898f\u8868\u73fe\u3067\u6700\u5b89\u5024\u3092\u53d6\u5f97\r\n    \/\/ &lt;span&gt;&amp;yen;\u306e\u5f8c\u306b\u6570\u5b57\u3068\u30ab\u30f3\u30de\u304c1\u3064\u4ee5\u4e0a\u7d9a\u304f\u6761\u4ef6\u3067\u691c\u7d22\u3002\r\n    var regex = new RegExp(&quot;\\&lt;span\\&gt;\\&amp;yen\\;([0-9,]+)&quot;);\r\n    \r\n    \/\/\u30de\u30c3\u30c1\u3057\u305f()\u5185\u306e\u6570\u5b57\u3092\u53d6\u5f97\r\n    var price = html.match(regex)[1];\r\n    \r\n    \/\/\u5546\u54c1\u540d\u3092\u30bb\u30eb\u306b\u66f8\u304d\u8fbc\u3080\r\n    aSheet.getRange(i, 2).setValue(itemName[0]);\r\n    \r\n    \/\/\u4fa1\u683c\u3092\u30bb\u30eb\u306b\u66f8\u304d\u8fbc\u3080\r\n    aSheet.getRange(i, 3).setValue(price);\r\n    \r\n  }\r\n}\r\n\r\nfunction getContentOfTagName(html, tagName) {\r\n  \r\n  var i = 0;\r\n  var j = 0;\r\n  var startOfTag;\r\n  var endOfTag;\r\n  var str = [ ];\r\n  \r\n  while(html.indexOf(&#039;&lt;&#039; + tagName,j)!=-1){\r\n    \r\n    \/\/&quot;&lt;\u30bf\u30b0\u540d&quot;\u306e\u958b\u59cb\u4f4d\u7f6e\u3092\u53d6\u5f97\r\n    j = html.indexOf(&#039;&lt;&#039; + tagName,j);\r\n    \r\n    \/\/\u6b21\u306e&quot;&gt;&quot;\u4f4d\u7f6e + 1\u3092\u6587\u5b57\u5217\u306e\u59cb\u3081\u3068\u3059\u308b\r\n    startOfStr = html.indexOf(&#039;&gt;&#039;,j)+1;\r\n    \r\n    \/\/\u6b21\u306e&quot;&lt;\/\u30bf\u30b0\u540d&gt;&quot;\u4f4d\u7f6e\u3092\u6587\u5b57\u5217\u306e\u7d42\u308f\u308a\u3068\u3059\u308b\r\n    endOfStr = html.indexOf(&#039;&lt;\/&#039; + tagName + &#039;&gt;&#039;,j);\r\n    \r\n    \/\/\u30bf\u30b0\u306e\u9593\u306e\u6587\u5b57\u5217\u3092\u914d\u5217\u306b\u8ffd\u52a0\r\n    str[i] = html.substring(startOfStr, endOfStr);\r\n    \r\n    j = endOfStr + 1;\r\n    i++;\r\n  }\r\n  \r\n  return str;\r\n}<\/code><\/pre><\/figure>\n<h2>\u5b9f\u884c\u7d50\u679c<\/h2>\n<p>\uff11\u5217\u76ee\u306b\u4fa1\u683ccom\u306e\u5546\u54c1URL\u3092\u5165\u308c\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/jidouka.work\/wp-content\/uploads\/2017\/11\/dbaf89f0759f364d539df36f78ab18e2.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/jidouka.work\/wp-content\/uploads\/2017\/11\/dbaf89f0759f364d539df36f78ab18e2.jpg\" alt=\"\" width=\"790\" height=\"284\" class=\"alignnone size-full wp-image-295\" srcset=\"https:\/\/jidouka.work\/wp-content\/uploads\/2017\/11\/dbaf89f0759f364d539df36f78ab18e2.jpg 790w, https:\/\/jidouka.work\/wp-content\/uploads\/2017\/11\/dbaf89f0759f364d539df36f78ab18e2-300x108.jpg 300w, https:\/\/jidouka.work\/wp-content\/uploads\/2017\/11\/dbaf89f0759f364d539df36f78ab18e2-768x276.jpg 768w\" sizes=\"auto, (max-width: 790px) 100vw, 790px\" \/><\/a><\/p>\n<p>\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u5b9f\u884c\u3057\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/jidouka.work\/wp-content\/uploads\/2017\/11\/4c48072c3163e1ca5888059395806d31.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/jidouka.work\/wp-content\/uploads\/2017\/11\/4c48072c3163e1ca5888059395806d31.jpg\" alt=\"\" width=\"788\" height=\"265\" class=\"alignnone size-full wp-image-296\" srcset=\"https:\/\/jidouka.work\/wp-content\/uploads\/2017\/11\/4c48072c3163e1ca5888059395806d31.jpg 788w, https:\/\/jidouka.work\/wp-content\/uploads\/2017\/11\/4c48072c3163e1ca5888059395806d31-300x101.jpg 300w, https:\/\/jidouka.work\/wp-content\/uploads\/2017\/11\/4c48072c3163e1ca5888059395806d31-768x258.jpg 768w\" sizes=\"auto, (max-width: 788px) 100vw, 788px\" \/><\/a><\/p>\n<p>\u81ea\u52d5\u7684\u306b\u5546\u54c1\u540d\u3068\u4fa1\u683c\u304c\u30bb\u30eb\u306b\u5165\u529b\u3055\u308c\u307e\u3057\u305f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5546\u54c1\u306e\u4fa1\u683c\u60c5\u5831\u3092\u7c21\u5358\u306b\u53d6\u5f97\u3057\u305f\u3044\u6642\u3068\u304b\u3042\u308a\u307e\u3059\u306d\u3002\u3055\u3089\u306b\u30ea\u30b9\u30c8\u306b\u3057\u3066\u4e00\u6c17\u306b\u53d6\u5f97\u3057\u305f\u3044\u3002\u53d6\u5f97\u3057\u305f\u4fa1\u683c\u60c5 &#8230; <\/p>\n","protected":false},"author":1,"featured_media":296,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[20],"class_list":["post-294","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-gas","tag-web"],"_links":{"self":[{"href":"https:\/\/jidouka.work\/index.php?rest_route=\/wp\/v2\/posts\/294","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jidouka.work\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jidouka.work\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jidouka.work\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jidouka.work\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=294"}],"version-history":[{"count":1,"href":"https:\/\/jidouka.work\/index.php?rest_route=\/wp\/v2\/posts\/294\/revisions"}],"predecessor-version":[{"id":297,"href":"https:\/\/jidouka.work\/index.php?rest_route=\/wp\/v2\/posts\/294\/revisions\/297"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/jidouka.work\/index.php?rest_route=\/wp\/v2\/media\/296"}],"wp:attachment":[{"href":"https:\/\/jidouka.work\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=294"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jidouka.work\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=294"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jidouka.work\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=294"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}