質問編集履歴
2
test
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,16 +1,6 @@
|
|
1
1
|
よろしくお願いします。
|
2
2
|
|
3
3
|
|
4
|
-
|
5
|
-
Puppeteerでのスクレイピングで、
|
6
|
-
|
7
|
-
MaxListeners()のデフォルトである10回を超える処理をすると
|
8
|
-
|
9
|
-
以下のエラーが出ます。
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
> MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 unhandledRejection listeners added. Use emitter.setMaxListeners() to increase limit
|
14
4
|
|
15
5
|
|
16
6
|
|
@@ -149,185 +139,3 @@
|
|
149
139
|
end
|
150
140
|
|
151
141
|
end
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
MaxListeners()の上限を増やすか、
|
156
|
-
|
157
|
-
上限をなくすことで警告が消えると考えているので、
|
158
|
-
|
159
|
-
その方法を教えていただきたいです。
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
環境は以下の通りです。
|
164
|
-
|
165
|
-
windows10
|
166
|
-
|
167
|
-
node 7.6.0
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
------- 追記です。
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
```typescript
|
176
|
-
|
177
|
-
// main.ts
|
178
|
-
|
179
|
-
import { fork } from "child_process";
|
180
|
-
|
181
|
-
const R = require("rambd");
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
const work = () => new Promise(resolve=>{
|
186
|
-
|
187
|
-
const child = fork("pup.ts", [], {
|
188
|
-
|
189
|
-
cwd : __dirname,
|
190
|
-
|
191
|
-
env : process.env,
|
192
|
-
|
193
|
-
})
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
child.on("message", result => {
|
198
|
-
|
199
|
-
return resolve(result)
|
200
|
-
|
201
|
-
})
|
202
|
-
|
203
|
-
})
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
const fn = async () => {
|
208
|
-
|
209
|
-
const promised = R.range(0, 12).map(() => work())
|
210
|
-
|
211
|
-
const result = await Promise.all(promised)
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
console.log(result, 'DONE')
|
216
|
-
|
217
|
-
}
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
fn()
|
222
|
-
|
223
|
-
})
|
224
|
-
|
225
|
-
```
|
226
|
-
|
227
|
-
```typescript
|
228
|
-
|
229
|
-
// pup.ts
|
230
|
-
|
231
|
-
const assert = require('assert');
|
232
|
-
|
233
|
-
const puppeteer = require('puppeteer');
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
const work = async () => {
|
238
|
-
|
239
|
-
process.on('unhandledRejection', console.dir);
|
240
|
-
|
241
|
-
const browser = await puppeteer.launch();
|
242
|
-
|
243
|
-
const page = await browser.newPage();
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
await page.goto('http://~~', {waitUntil: 'networkidle2'});
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
await page.focus('input[name="username"]');
|
252
|
-
|
253
|
-
await page.type('xxxxx');
|
254
|
-
|
255
|
-
await page.focus('input[name="password"]');
|
256
|
-
|
257
|
-
await page.type('yyyyy');
|
258
|
-
|
259
|
-
const buttonElement = await page.$('button[type=submit]');
|
260
|
-
|
261
|
-
await buttonElement.click();
|
262
|
-
|
263
|
-
await page.waitFor(5000);
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
const selecterResult = await page.evaluate(() => {
|
268
|
-
|
269
|
-
const node = document.body.querySelector('span');
|
270
|
-
|
271
|
-
return node.tagName;
|
272
|
-
|
273
|
-
});
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
await browser.close();
|
278
|
-
|
279
|
-
return 'end';
|
280
|
-
|
281
|
-
}
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
work()
|
286
|
-
|
287
|
-
.then(result => {
|
288
|
-
|
289
|
-
process.send(result)
|
290
|
-
|
291
|
-
process.exit()
|
292
|
-
|
293
|
-
})
|
294
|
-
|
295
|
-
```
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
結果は以下の通りです。
|
300
|
-
|
301
|
-
> module.js:472
|
302
|
-
|
303
|
-
throw err;
|
304
|
-
|
305
|
-
^
|
306
|
-
|
307
|
-
Error: Cannot find module 'rambda'
|
308
|
-
|
309
|
-
at Function.Module._resolveFilename (module.js:470:15)
|
310
|
-
|
311
|
-
at Function.Module._load (module.js:418:25)
|
312
|
-
|
313
|
-
at Module.require (module.js:498:17)
|
314
|
-
|
315
|
-
at require (internal/module.js:20:19)
|
316
|
-
|
317
|
-
at Object.<anonymous> (path:4:11)
|
318
|
-
|
319
|
-
at Module._compile (module.js:571:32)
|
320
|
-
|
321
|
-
at Object.Module._extensions..js (module.js:580:10)
|
322
|
-
|
323
|
-
at Module.load (module.js:488:32)
|
324
|
-
|
325
|
-
at tryModuleLoad (module.js:447:12)
|
326
|
-
|
327
|
-
at Function.Module._load (module.js:439:3)
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
rambdaを利用していないので当然といえば当然ですが、
|
332
|
-
|
333
|
-
使わないと実装できないのでしょうか?
|
1
参考リンクを元に実装、結果
test
CHANGED
File without changes
|
test
CHANGED
@@ -165,3 +165,169 @@
|
|
165
165
|
windows10
|
166
166
|
|
167
167
|
node 7.6.0
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
------- 追記です。
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
```typescript
|
176
|
+
|
177
|
+
// main.ts
|
178
|
+
|
179
|
+
import { fork } from "child_process";
|
180
|
+
|
181
|
+
const R = require("rambd");
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
const work = () => new Promise(resolve=>{
|
186
|
+
|
187
|
+
const child = fork("pup.ts", [], {
|
188
|
+
|
189
|
+
cwd : __dirname,
|
190
|
+
|
191
|
+
env : process.env,
|
192
|
+
|
193
|
+
})
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
child.on("message", result => {
|
198
|
+
|
199
|
+
return resolve(result)
|
200
|
+
|
201
|
+
})
|
202
|
+
|
203
|
+
})
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
const fn = async () => {
|
208
|
+
|
209
|
+
const promised = R.range(0, 12).map(() => work())
|
210
|
+
|
211
|
+
const result = await Promise.all(promised)
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
console.log(result, 'DONE')
|
216
|
+
|
217
|
+
}
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
fn()
|
222
|
+
|
223
|
+
})
|
224
|
+
|
225
|
+
```
|
226
|
+
|
227
|
+
```typescript
|
228
|
+
|
229
|
+
// pup.ts
|
230
|
+
|
231
|
+
const assert = require('assert');
|
232
|
+
|
233
|
+
const puppeteer = require('puppeteer');
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
const work = async () => {
|
238
|
+
|
239
|
+
process.on('unhandledRejection', console.dir);
|
240
|
+
|
241
|
+
const browser = await puppeteer.launch();
|
242
|
+
|
243
|
+
const page = await browser.newPage();
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
await page.goto('http://~~', {waitUntil: 'networkidle2'});
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
await page.focus('input[name="username"]');
|
252
|
+
|
253
|
+
await page.type('xxxxx');
|
254
|
+
|
255
|
+
await page.focus('input[name="password"]');
|
256
|
+
|
257
|
+
await page.type('yyyyy');
|
258
|
+
|
259
|
+
const buttonElement = await page.$('button[type=submit]');
|
260
|
+
|
261
|
+
await buttonElement.click();
|
262
|
+
|
263
|
+
await page.waitFor(5000);
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
const selecterResult = await page.evaluate(() => {
|
268
|
+
|
269
|
+
const node = document.body.querySelector('span');
|
270
|
+
|
271
|
+
return node.tagName;
|
272
|
+
|
273
|
+
});
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
await browser.close();
|
278
|
+
|
279
|
+
return 'end';
|
280
|
+
|
281
|
+
}
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
work()
|
286
|
+
|
287
|
+
.then(result => {
|
288
|
+
|
289
|
+
process.send(result)
|
290
|
+
|
291
|
+
process.exit()
|
292
|
+
|
293
|
+
})
|
294
|
+
|
295
|
+
```
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
結果は以下の通りです。
|
300
|
+
|
301
|
+
> module.js:472
|
302
|
+
|
303
|
+
throw err;
|
304
|
+
|
305
|
+
^
|
306
|
+
|
307
|
+
Error: Cannot find module 'rambda'
|
308
|
+
|
309
|
+
at Function.Module._resolveFilename (module.js:470:15)
|
310
|
+
|
311
|
+
at Function.Module._load (module.js:418:25)
|
312
|
+
|
313
|
+
at Module.require (module.js:498:17)
|
314
|
+
|
315
|
+
at require (internal/module.js:20:19)
|
316
|
+
|
317
|
+
at Object.<anonymous> (path:4:11)
|
318
|
+
|
319
|
+
at Module._compile (module.js:571:32)
|
320
|
+
|
321
|
+
at Object.Module._extensions..js (module.js:580:10)
|
322
|
+
|
323
|
+
at Module.load (module.js:488:32)
|
324
|
+
|
325
|
+
at tryModuleLoad (module.js:447:12)
|
326
|
+
|
327
|
+
at Function.Module._load (module.js:439:3)
|
328
|
+
|
329
|
+
|
330
|
+
|
331
|
+
rambdaを利用していないので当然といえば当然ですが、
|
332
|
+
|
333
|
+
使わないと実装できないのでしょうか?
|