質問編集履歴

3

function test()を実行した際のログを表示しました。

2018/10/04 03:50

投稿

ryu01212008
ryu01212008

スコア26

test CHANGED
File without changes
test CHANGED
@@ -355,3 +355,15 @@
355
355
  }
356
356
 
357
357
  ```
358
+
359
+
360
+
361
+ ###function test()を実行した際のログを表示します。
362
+
363
+ ```GAS
364
+
365
+ [18-10-04 12:47:05:886 JST] searchStartKey not found
366
+
367
+ [18-10-04 12:47:05:887 JST] asin:null
368
+
369
+ ```

2

searchByに関して詳細を追記しました。

2018/10/04 03:50

投稿

ryu01212008
ryu01212008

スコア26

test CHANGED
File without changes
test CHANGED
@@ -273,3 +273,85 @@
273
273
 
274
274
 
275
275
  ```
276
+
277
+
278
+
279
+ searchByに関して追記します。
280
+
281
+ ```GAS
282
+
283
+ /*
284
+
285
+ target 検索対象
286
+
287
+ startKey 検索開始文字列
288
+
289
+ endKey 検索終了文字列
290
+
291
+ searchStartKey 検索対象開始文字列
292
+
293
+ ※なしの場合は検索対象全てから検索
294
+
295
+ searchLength 検索対象文字数
296
+
297
+ ※なしの場合は検索対象開始文字列以降全てから検索
298
+
299
+ searchRepeat 検索繰り返し回数
300
+
301
+ */
302
+
303
+ function searchBy (target, startKey, endKey, searchStartKey, searchLength, searchRepeat) {
304
+
305
+ // 検索開始文字列があった場合のみ
306
+
307
+ if (searchStartKey) {
308
+
309
+ var index = target.indexOf(searchStartKey)
310
+
311
+ for (var c = 0; searchRepeat && c < searchRepeat; c++) {
312
+
313
+ index = target.indexOf(searchStartKey, index + 1)
314
+
315
+ }
316
+
317
+
318
+
319
+ if (index === -1) {
320
+
321
+ Logger.log("searchStartKey not found")
322
+
323
+ return null
324
+
325
+ }
326
+
327
+
328
+
329
+ // 指定文字数取得して検索対象を更新
330
+
331
+ target = target.substring(index + searchStartKey.length,
332
+
333
+ searchLength ? index + searchStartKey.length + searchLength : target.length)
334
+
335
+ }
336
+
337
+
338
+
339
+ var startIndex = startKey !== null ? target.indexOf(startKey) + startKey.length : 0
340
+
341
+ var endIndex = endKey !== null ? target.indexOf(endKey, startIndex) : target.length
342
+
343
+
344
+
345
+ if ((startKey === null || startIndex !== (startKey.length - 1)) && endIndex !== -1) {
346
+
347
+ return target.substring(startIndex, endIndex)
348
+
349
+ } else {
350
+
351
+ return null
352
+
353
+ }
354
+
355
+ }
356
+
357
+ ```

1

質問に回答させていただきました。

2018/10/03 01:10

投稿

ryu01212008
ryu01212008

スコア26

test CHANGED
File without changes
test CHANGED
@@ -229,3 +229,47 @@
229
229
  ###補足情報
230
230
 
231
231
  function searchByの独自関数は問題なく機能しています。
232
+
233
+
234
+
235
+ ###papinianusの質問に回答します。
236
+
237
+ currentRowIndex++のインデント位置からしてifかなにかを削っているはず。に関してですが、商品画像URLの前にASINコードを用意しています。
238
+
239
+
240
+
241
+ ```
242
+
243
+
244
+
245
+
246
+
247
+
248
+
249
+ for (var si = 0; si < 10000; si++) {
250
+
251
+ // ASIN
252
+
253
+ var asin = searchBy(rootHtml, '<div data-caution="', '">', 'class="search_item_list_section"', 100000, si)
254
+
255
+ if (!asin) {
256
+
257
+ break
258
+
259
+ }
260
+
261
+ values[currentRowIndex - 2] = []
262
+
263
+ values[currentRowIndex - 2].push(asin || '該当データ無し')
264
+
265
+
266
+
267
+ // 商品画像URL
268
+
269
+
270
+
271
+
272
+
273
+
274
+
275
+ ```