質問編集履歴

10

追加事項の修正

2024/03/15 06:20

投稿

studiosimply
studiosimply

スコア4

test CHANGED
File without changes
test CHANGED
@@ -213,7 +213,7 @@
213
213
  > personalSKD[1][2]: 3月21日(木)
214
214
  と正しいです。
215
215
 
216
- しかしソースコード120行でのコンソール表示は、
216
+ しかしソースコード121行でのコンソール表示は、
217
217
  > personalSKD[0]: 3月19日(火),3月20日(水),3月21日(木)
218
218
  > personalSKD[1]: 3月19日(火),3月20日(水),3月21日(木)
219
219
  と personalSKD[0] の内容が変わっています。

9

ソースコードのコメント追加

2024/03/15 06:07

投稿

studiosimply
studiosimply

スコア4

test CHANGED
File without changes
test CHANGED
@@ -151,6 +151,7 @@
151
151
  name = companionInfo[i][1];
152
152
  age = companionInfo[i][2];
153
153
  isWorkDay = companionInfo[i][5];
154
+ // タイトルの作成準備をする
154
155
  if (isWorkDay == true) {
155
156
  subjectPeople.push(name + '('+ age +')');
156
157
  }

8

不正と見られる挙動を追加した。

2024/03/15 05:30

投稿

studiosimply
studiosimply

スコア4

test CHANGED
File without changes
test CHANGED
@@ -196,4 +196,25 @@
196
196
  - 配列の初期化を for 文ではなく、Array 文にした。
197
197
  - Logger.log 文を多用し、変数の値を見える化した。
198
198
 
199
-
199
+ ### 不正と見られる挙動
200
+
201
+ companionArr を
202
+
203
+ 'りお(25)','大宮人妻城'
204
+ '理沙(28)','大宮人妻花壇'
205
+ の上記2人の配列で実行した場合、
206
+ ソースコードの83行のコンソール表示は、
207
+ **りお(25)**
208
+ > personalSKD[0][0]: 3月15日(金)
209
+ **理沙(28)**
210
+ > personalSKD[1][0]: 3月19日(火)
211
+ > personalSKD[1][1]: 3月20日(水)
212
+ > personalSKD[1][2]: 3月21日(木)
213
+ と正しいです。
214
+
215
+ しかしソースコード120行でのコンソール表示は、
216
+ > personalSKD[0]: 3月19日(火),3月20日(水),3月21日(木)
217
+ > personalSKD[1]: 3月19日(火),3月20日(水),3月21日(木)
218
+ と personalSKD[0] の内容が変わっています。
219
+
220
+ 途中で変化する要素がないのに、中身が変わっているので理解できません。

7

コードのコメント更新

2024/03/15 03:34

投稿

studiosimply
studiosimply

スコア4

test CHANGED
File without changes
test CHANGED
@@ -110,7 +110,7 @@
110
110
  Logger.log(name +': 身長・3サイズなし');
111
111
  return;
112
112
  }
113
- // 出勤を取得する
113
+ // 出勤の有無を取得する
114
114
  var isWorkDay = false;
115
115
  if (/<ul class="mgnaviProfileSchedule">[\s\S]+?<\/ul>/.test) {
116
116
  var schedule = src.match(/<ul class="mgnaviProfileSchedule">[\s\S]+?<\/ul>/)[0];

6

ソースコードと失敗例の更新

2024/03/15 02:02

投稿

studiosimply
studiosimply

スコア4

test CHANGED
File without changes
test CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  ### 前提
6
6
 
7
- Google Apps Script で、スクレイピングをしています。コンパニオン派遣サービスをWeb上からスクレイピングして特定のコンパニオンの出勤日を取得したいのですが、companionArr の先頭2人のみ実行した場合はうまくいくのですが、3人以上指定した場合うまくいってた1~2人目の出勤日も空っぽになってしまいます。
7
+ Google Apps Script で、スクレイピングをしています。コンパニオン派遣サービスをWeb上からスクレイピングして特定のコンパニオンの出勤日を取得したいのですが、companionArr の先頭2人のみ実行した場合はうまくいくのですが、3人以上指定した場合、現在以下通りです。
8
8
 
9
9
  ### 先頭2人のみ実行した場合は出勤日を取得できている。
10
10
 
@@ -15,7 +15,19 @@
15
15
  > 3月14日(木),3月15日(金)
16
16
  > https://www.deli-more.com/lady/146218
17
17
 
18
+ ### 先頭3人を実行した場合は、出勤日が '理沙' に引っ張られている。
19
+
20
+ > 体験入店, 💗りお, (25), 大宮人妻花壇, T163-B83(B)-W57-H84
21
+ > 3月19日(火),3月20日(水),3月21日(木)
22
+ > https://www.deli-more.com/lady/146217
23
+ > 体験入店, 💗りお, (25), 大宮人妻城, T163-B83(B)-W57-H84
24
+ > 3月19日(火),3月20日(水),3月21日(木)
25
+ > https://www.deli-more.com/lady/146218
26
+ > 新人, 💗理沙, (28), 大宮人妻花壇, T155-B86(E)-W59-H85
27
+ > 3月19日(火),3月20日(水),3月21日(木)
28
+ > https://www.deli-more.com/lady/143730
29
+
18
- ### 先頭3人を実行した場合は出勤日が無くなっている。
30
+ ### 全員を実行した場合は出勤するはずの先頭3人の出勤日が無くなっている。
19
31
 
20
32
  > 体験入店, 💗りお, (25), 大宮人妻花壇, T163-B83(B)-W57-H84
21
33
  >
@@ -23,8 +35,23 @@
23
35
  > 体験入店, 💗りお, (25), 大宮人妻城, T163-B83(B)-W57-H84
24
36
  >
25
37
  > https://www.deli-more.com/lady/146218
38
+ > 新人, 💗理沙, (28), 大宮人妻花壇, T155-B86(E)-W59-H85
39
+ >
40
+ > https://www.deli-more.com/lady/143730
26
41
  > ----, 💙さつき, (34), 川越人妻花壇, T162-B83(B)-W59-H84
27
42
  > https://www.deli-more.com/lady/110691
43
+ > ----, 💙すず, (30), 川越人妻花壇, T160-B83(B)-W57-H84
44
+ > https://www.deli-more.com/lady/112026
45
+ > ----, 💙あやめ, (27), 大宮人妻花壇, T163-B83(B)-W57-H85
46
+ > https://www.deli-more.com/lady/130892
47
+ > ----, 💙有希子, (28), 大宮人妻城, T163-B82(B)-W57-H85
48
+ > https://www.deli-more.com/lady/135221
49
+ > ----, 💙有希子, (28), 大宮人妻花壇, T163-B82(B)-W57-H85
50
+ > https://www.deli-more.com/lady/135220
51
+ > ----, 💙蘭, (29), 大宮人妻城, T162-B83(B)-W57-H85
52
+ > https://www.deli-more.com/lady/140489
53
+ > ----, 💙蘭, (29), 大宮人妻花壇, T162-B83(B)-W57-H85
54
+ > https://www.deli-more.com/lady/140488
28
55
 
29
56
  ### 該当のソースコード
30
57
 
@@ -100,16 +127,16 @@
100
127
  // 出勤日を取得する
101
128
  if (isWorkDay == true) {
102
129
  // 1週間を1日ずつ配列に格納する
103
- schedDays = schedule.match(/<li>\s*?<div class="mgnaviProfileScheduleDate">.+?<\/div>\s*?<div class="mgnaviProfileScheduleTime">\s*?<span>.+?<\/span><span>~<\/span><span>.+?<\/span>\s*?<\/div>\s*?<\/li>/g);
104
- Logger.log('schedDays.length: '+ schedDays.length);
105
-
106
- for (var j=0; j < schedDays.length; j++) {
107
- Logger.log('schedDays['+ j +']: '+ schedDays[j]);
130
+ schedScripts = schedule.match(/<li>\s*?<div class="mgnaviProfileScheduleDate">.+?<\/div>\s*?<div class="mgnaviProfileScheduleTime">\s*?<span>.+?<\/span><span>~<\/span><span>.+?<\/span>\s*?<\/div>\s*?<\/li>/g);
131
+
132
+ Logger.log('schedScripts.length: '+ schedScripts.length);
133
+ for (var j=0; j < schedScripts.length; j++) {
134
+ Logger.log('schedScripts['+ j +']: '+ schedScripts[j]);
108
135
  }
109
136
 
110
137
  // 出勤日を配列に格納する
111
- for (var j=0; j < schedDays.length; j++) { // j は、その人の出勤日数を表す
112
- var date = schedDays[j].match(/<li>\s*?<div class="mgnaviProfileScheduleDate">(.+?)<\/div>\s*?<div class="mgnaviProfileScheduleTime">\s*?<span>.+?<\/span><span>~<\/span><span>.+?<\/span>\s*?<\/div>\s*?<\/li>/)[1];
138
+ for (var j=0; j < schedScripts.length; j++) { // j は、その人の出勤日数を表す
139
+ var date = schedScripts[j].match(/<li>\s*?<div class="mgnaviProfileScheduleDate">(.+?)<\/div>\s*?<div class="mgnaviProfileScheduleTime">\s*?<span>.+?<\/span><span>~<\/span><span>.+?<\/span>\s*?<\/div>\s*?<\/li>/)[1];
113
140
  personalSKD[i].push(date);
114
141
  Logger.log('personalSKD['+ i +']['+ j +']: '+ personalSKD[i][j]);
115
142
  }

5

ソースコードを変更した

2024/03/15 01:36

投稿

studiosimply
studiosimply

スコア4

test CHANGED
File without changes
test CHANGED
@@ -35,9 +35,9 @@
35
35
  var companionArr = [
36
36
  ['https://www.deli-more.com/lady/146217','りお(25)','大宮人妻花壇','T163-B83(B)-W57-H84'],
37
37
  ['https://www.deli-more.com/lady/146218','りお(25)','大宮人妻城','T163-B83(B)-W57-H84'],
38
- // ['https://www.deli-more.com/lady/143730','理沙(28)','大宮人妻花壇','T155-B86(E)-W59-H85'], // ダミー
38
+ /* ['https://www.deli-more.com/lady/143730','理沙(28)','大宮人妻花壇','T155-B86(E)-W59-H85'], // ダミー
39
- // ['https://www.deli-more.com/lady/110691','さつき(34)','川越人妻花壇','T162-B83(B)-W59-H84'],
39
+ ['https://www.deli-more.com/lady/110691','さつき(34)','川越人妻花壇','T162-B83(B)-W59-H84'],
40
- /* ['https://www.deli-more.com/lady/112026','すず(30)','川越人妻花壇','T160-B83(B)-W57-H84'],
40
+ ['https://www.deli-more.com/lady/112026','すず(30)','川越人妻花壇','T160-B83(B)-W57-H84'],
41
41
  ['https://www.deli-more.com/lady/130892','あやめ(27)','大宮人妻花壇','T163-B83(B)-W57-H85'],
42
42
  ['https://www.deli-more.com/lady/135221','有希子(28)','大宮人妻城','T163-B82(B)-W57-H85'],
43
43
  ['https://www.deli-more.com/lady/135220','有希子(28)','大宮人妻花壇','T163-B82(B)-W57-H85'],
@@ -107,7 +107,6 @@
107
107
  Logger.log('schedDays['+ j +']: '+ schedDays[j]);
108
108
  }
109
109
 
110
-
111
110
  // 出勤日を配列に格納する
112
111
  for (var j=0; j < schedDays.length; j++) { // j は、その人の出勤日数を表す
113
112
  var date = schedDays[j].match(/<li>\s*?<div class="mgnaviProfileScheduleDate">(.+?)<\/div>\s*?<div class="mgnaviProfileScheduleTime">\s*?<span>.+?<\/span><span>~<\/span><span>.+?<\/span>\s*?<\/div>\s*?<\/li>/)[1];
@@ -148,7 +147,8 @@
148
147
  companionUrl = companionInfo[i][6];
149
148
  message += status +', '+ (isWorkDay ? '💗' : '💙') + name +', ('+ age +'), '+ shop +', '+ size +'\n';
150
149
  // 出勤日を追加する
151
- if (isWorkDay) {
150
+ if (isWorkDay == true) {
151
+ Logger.log('personalSKD['+ i +']: '+ personalSKD[i]);
152
152
  message += personalSKD[i] +'\n';
153
153
  }
154
154
  message += companionUrl +'\n';

4

正規表現が不適切だったので修正した

2024/03/15 01:11

投稿

studiosimply
studiosimply

スコア4

test CHANGED
File without changes
test CHANGED
@@ -30,20 +30,20 @@
30
30
 
31
31
  ```GAS
32
32
  function companionAttendanceNotification() {
33
-
33
+
34
- // コンパニオンの配列
34
+ // コンパニオンの配列
35
- var companionArr = [
35
+ var companionArr = [
36
36
  ['https://www.deli-more.com/lady/146217','りお(25)','大宮人妻花壇','T163-B83(B)-W57-H84'],
37
37
  ['https://www.deli-more.com/lady/146218','りお(25)','大宮人妻城','T163-B83(B)-W57-H84'],
38
+ // ['https://www.deli-more.com/lady/143730','理沙(28)','大宮人妻花壇','T155-B86(E)-W59-H85'], // ダミー
38
- /* ['https://www.deli-more.com/lady/110691','さつき(34)','川越人妻花壇','T162-B83(B)-W59-H84'],
39
+ // ['https://www.deli-more.com/lady/110691','さつき(34)','川越人妻花壇','T162-B83(B)-W59-H84'],
39
- ['https://www.deli-more.com/lady/112026','すず(30)','川越人妻花壇','T160-B83(B)-W57-H84'],
40
+ /* ['https://www.deli-more.com/lady/112026','すず(30)','川越人妻花壇','T160-B83(B)-W57-H84'],
40
41
  ['https://www.deli-more.com/lady/130892','あやめ(27)','大宮人妻花壇','T163-B83(B)-W57-H85'],
41
42
  ['https://www.deli-more.com/lady/135221','有希子(28)','大宮人妻城','T163-B82(B)-W57-H85'],
42
43
  ['https://www.deli-more.com/lady/135220','有希子(28)','大宮人妻花壇','T163-B82(B)-W57-H85'],
43
44
  ['https://www.deli-more.com/lady/140489','蘭(29)','大宮人妻城','T162-B83(B)-W57-H85'],
44
45
  ['https://www.deli-more.com/lady/140488','蘭(29)','大宮人妻花壇','T162-B83(B)-W57-H85'],*/
45
46
  ];
46
-
47
47
  // 各コンパニオンページへアクセスする
48
48
  var companionInfo = [];
49
49
  var options = { method: "get" };
@@ -51,11 +51,11 @@
51
51
  var companionUrl = companionArr[i][0];
52
52
  var name = companionArr[i][1];
53
53
  Logger.log(name +'…');
54
-
54
+
55
55
  // コンパニオンページを取得する
56
56
  response = UrlFetchApp.fetch(companionUrl, options);
57
57
  var src = response.getContentText();
58
-
58
+
59
59
  // ステータス・名前・年齢を取得する
60
60
  if (/<p class="mgnaviProfileName"><span class=".+?">.+?<\/span>.+?<span class="mgnaviProfileAge">\(.+?\)<\/span><\/p>/.test(src)) {
61
61
  var status = src.match(/<p class="mgnaviProfileName"><span class=".+?">(.+?)<\/span>.+?<span class="mgnaviProfileAge">\(.+?\)<\/span><\/p>/)[1];
@@ -70,8 +70,8 @@
70
70
  return;
71
71
  }
72
72
  // 店名を取得する
73
- if (/<div>[\s\S]*?.+?<a class="mgnavProfileShoptellink" href=".+?">.+?<\/a>[\s\S]*?<\/div>/.test(src)) {
73
+ if (/<div>\s*?.+?<a class="mgnavProfileShoptellink" href=".+?">.+?<\/a>\s*?<\/div>/.test(src)) {
74
- var shop = src.match(/<div>[\s\S]*?(.+?)<a class="mgnavProfileShoptellink" href=".+?">.+?<\/a>[\s\S]*?<\/div>/)[1].trim();
74
+ var shop = src.match(/<div>\s*?(.+?)<a class="mgnavProfileShoptellink" href=".+?">.+?<\/a>\s*?<\/div>/)[1].trim();
75
75
  } else {
76
76
  Logger.log(name +': 店名なし');
77
77
  return;
@@ -96,19 +96,25 @@
96
96
 
97
97
  // 出勤日の配列を初期化する
98
98
  var personalSKD = Array(companionArr.length).fill([]);
99
-
99
+
100
100
  // 出勤日を取得する
101
101
  if (isWorkDay == true) {
102
102
  // 1週間を1日ずつ配列に格納する
103
- schedDay = schedule.match(/<div class="mgnaviProfileScheduleDate">.+?<\/div>[\s\S]*?<div class="mgnaviProfileScheduleTime">[\s\S]*?<span>.+?<\/span><span>~<\/span><span>.+?<\/span>[\s\S]*?<\/div>/g);
104
-
103
+ schedDays = schedule.match(/<li>\s*?<div class="mgnaviProfileScheduleDate">.+?<\/div>\s*?<div class="mgnaviProfileScheduleTime">\s*?<span>.+?<\/span><span>~<\/span><span>.+?<\/span>\s*?<\/div>\s*?<\/li>/g);
104
+ Logger.log('schedDays.length: '+ schedDays.length);
105
+
106
+ for (var j=0; j < schedDays.length; j++) {
107
+ Logger.log('schedDays['+ j +']: '+ schedDays[j]);
108
+ }
109
+
110
+
105
111
  // 出勤日を配列に格納する
106
- for (var j=0; j < schedDay.length; j++) { // j は、その人の出勤日数を表す
107
- var date = schedDay[j].match(/<div class="mgnaviProfileScheduleDate">(.+?)<\/div>[\s\S]*?<div class="mgnaviProfileScheduleTime">[\s\S]*?<span>.+?<\/span><span>~<\/span><span>.+?<\/span>[\s\S]*?<\/div>/)[1];
112
+ for (var j=0; j < schedDays.length; j++) { // j は、その人の出勤日数を表す
113
+ var date = schedDays[j].match(/<li>\s*?<div class="mgnaviProfileScheduleDate">(.+?)<\/div>\s*?<div class="mgnaviProfileScheduleTime">\s*?<span>.+?<\/span><span>~<\/span><span>.+?<\/span>\s*?<\/div>\s*?<\/li>/)[1];
108
114
  personalSKD[i].push(date);
115
+ Logger.log('personalSKD['+ i +']['+ j +']: '+ personalSKD[i][j]);
109
116
  }
110
117
  }
111
-
112
118
  // コンパニオンの情報を配列に格納する
113
119
  companionInfo.push([status, name, age, shop, size, isWorkDay, companionUrl]);
114
120
  }

3

ソースコードを見やすくした

2024/03/15 00:06

投稿

studiosimply
studiosimply

スコア4

test CHANGED
File without changes
test CHANGED
@@ -51,6 +51,8 @@
51
51
  var companionUrl = companionArr[i][0];
52
52
  var name = companionArr[i][1];
53
53
  Logger.log(name +'…');
54
+
55
+ // コンパニオンページを取得する
54
56
  response = UrlFetchApp.fetch(companionUrl, options);
55
57
  var src = response.getContentText();
56
58
 

2

前提の読みやすさ

2024/03/14 15:10

投稿

studiosimply
studiosimply

スコア4

test CHANGED
File without changes
test CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  ### 前提
6
6
 
7
- Google Apps Script で、スクレイピングをしています。コンパニオン派遣サービスをWeb上からスクレイピングして特定のコンパニオンの出勤日を取得したいのですが、companionArr の先頭2人のみ実行した場合はうまくいくのですが、3人以上指定した場合は、うまくいってたはずの1~2人目の出勤日も空っぽになってしま
7
+ Google Apps Script で、スクレイピングをしています。コンパニオン派遣サービスをWeb上からスクレイピングして特定のコンパニオンの出勤日を取得したいのですが、companionArr の先頭2人のみ実行した場合はうまくいくのですが、3人以上指定した場合は、うまくいってたはずの1~2人目の出勤日も空っぽになってしまいます
8
8
 
9
9
  ### 先頭2人のみ実行した場合は出勤日を取得できている。
10
10
 

1

ソースコードを見やすくした。

2024/03/14 15:03

投稿

studiosimply
studiosimply

スコア4

test CHANGED
File without changes
test CHANGED
@@ -30,7 +30,9 @@
30
30
 
31
31
  ```GAS
32
32
  function companionAttendanceNotification() {
33
+
34
+ // コンパニオンの配列
33
- var companionArr = [
35
+ var companionArr = [
34
36
  ['https://www.deli-more.com/lady/146217','りお(25)','大宮人妻花壇','T163-B83(B)-W57-H84'],
35
37
  ['https://www.deli-more.com/lady/146218','りお(25)','大宮人妻城','T163-B83(B)-W57-H84'],
36
38
  /* ['https://www.deli-more.com/lady/110691','さつき(34)','川越人妻花壇','T162-B83(B)-W59-H84'],
@@ -51,6 +53,7 @@
51
53
  Logger.log(name +'…');
52
54
  response = UrlFetchApp.fetch(companionUrl, options);
53
55
  var src = response.getContentText();
56
+
54
57
  // ステータス・名前・年齢を取得する
55
58
  if (/<p class="mgnaviProfileName"><span class=".+?">.+?<\/span>.+?<span class="mgnaviProfileAge">\(.+?\)<\/span><\/p>/.test(src)) {
56
59
  var status = src.match(/<p class="mgnaviProfileName"><span class=".+?">(.+?)<\/span>.+?<span class="mgnaviProfileAge">\(.+?\)<\/span><\/p>/)[1];
@@ -91,6 +94,7 @@
91
94
 
92
95
  // 出勤日の配列を初期化する
93
96
  var personalSKD = Array(companionArr.length).fill([]);
97
+
94
98
  // 出勤日を取得する
95
99
  if (isWorkDay == true) {
96
100
  // 1週間を1日ずつ配列に格納する
@@ -134,7 +138,6 @@
134
138
  size = companionInfo[i][4];
135
139
  isWorkDay = companionInfo[i][5];
136
140
  companionUrl = companionInfo[i][6];
137
-
138
141
  message += status +', '+ (isWorkDay ? '💗' : '💙') + name +', ('+ age +'), '+ shop +', '+ size +'\n';
139
142
  // 出勤日を追加する
140
143
  if (isWorkDay) {