質問編集履歴
3
function test()を実行した際のログを表示しました。
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -176,4 +176,10 @@
|
|
|
176
176
|
return null
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
###function test()を実行した際のログを表示します。
|
|
182
|
+
```GAS
|
|
183
|
+
[18-10-04 12:47:05:886 JST] searchStartKey not found
|
|
184
|
+
[18-10-04 12:47:05:887 JST] asin:null
|
|
179
185
|
```
|
2
searchByに関して詳細を追記しました。
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -135,4 +135,45 @@
|
|
|
135
135
|
・
|
|
136
136
|
・
|
|
137
137
|
・
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
searchByに関して追記します。
|
|
141
|
+
```GAS
|
|
142
|
+
/*
|
|
143
|
+
target 検索対象
|
|
144
|
+
startKey 検索開始文字列
|
|
145
|
+
endKey 検索終了文字列
|
|
146
|
+
searchStartKey 検索対象開始文字列
|
|
147
|
+
※なしの場合は検索対象全てから検索
|
|
148
|
+
searchLength 検索対象文字数
|
|
149
|
+
※なしの場合は検索対象開始文字列以降全てから検索
|
|
150
|
+
searchRepeat 検索繰り返し回数
|
|
151
|
+
*/
|
|
152
|
+
function searchBy (target, startKey, endKey, searchStartKey, searchLength, searchRepeat) {
|
|
153
|
+
// 検索開始文字列があった場合のみ
|
|
154
|
+
if (searchStartKey) {
|
|
155
|
+
var index = target.indexOf(searchStartKey)
|
|
156
|
+
for (var c = 0; searchRepeat && c < searchRepeat; c++) {
|
|
157
|
+
index = target.indexOf(searchStartKey, index + 1)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (index === -1) {
|
|
161
|
+
Logger.log("searchStartKey not found")
|
|
162
|
+
return null
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// 指定文字数取得して検索対象を更新
|
|
166
|
+
target = target.substring(index + searchStartKey.length,
|
|
167
|
+
searchLength ? index + searchStartKey.length + searchLength : target.length)
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
var startIndex = startKey !== null ? target.indexOf(startKey) + startKey.length : 0
|
|
171
|
+
var endIndex = endKey !== null ? target.indexOf(endKey, startIndex) : target.length
|
|
172
|
+
|
|
173
|
+
if ((startKey === null || startIndex !== (startKey.length - 1)) && endIndex !== -1) {
|
|
174
|
+
return target.substring(startIndex, endIndex)
|
|
175
|
+
} else {
|
|
176
|
+
return null
|
|
177
|
+
}
|
|
178
|
+
}
|
|
138
179
|
```
|
1
質問に回答させていただきました。
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -113,4 +113,26 @@
|
|
|
113
113
|
for (var si = "0"; si < "10000"; si++) {
|
|
114
114
|
```
|
|
115
115
|
###補足情報
|
|
116
|
-
function searchByの独自関数は問題なく機能しています。
|
|
116
|
+
function searchByの独自関数は問題なく機能しています。
|
|
117
|
+
|
|
118
|
+
###papinianusの質問に回答します。
|
|
119
|
+
currentRowIndex++のインデント位置からしてifかなにかを削っているはず。に関してですが、商品画像URLの前にASINコードを用意しています。
|
|
120
|
+
|
|
121
|
+
```
|
|
122
|
+
・
|
|
123
|
+
・
|
|
124
|
+
・
|
|
125
|
+
for (var si = 0; si < 10000; si++) {
|
|
126
|
+
// ASIN
|
|
127
|
+
var asin = searchBy(rootHtml, '<div data-caution="', '">', 'class="search_item_list_section"', 100000, si)
|
|
128
|
+
if (!asin) {
|
|
129
|
+
break
|
|
130
|
+
}
|
|
131
|
+
values[currentRowIndex - 2] = []
|
|
132
|
+
values[currentRowIndex - 2].push(asin || '該当データ無し')
|
|
133
|
+
|
|
134
|
+
// 商品画像URL
|
|
135
|
+
・
|
|
136
|
+
・
|
|
137
|
+
・
|
|
138
|
+
```
|