質問編集履歴
2
test
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,11 +1,6 @@
|
|
1
1
|
よろしくお願いします。
|
2
2
|
|
3
|
-
Puppeteerでのスクレイピングで、
|
4
|
-
MaxListeners()のデフォルトである10回を超える処理をすると
|
5
|
-
以下のエラーが出ます。
|
6
3
|
|
7
|
-
> MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 unhandledRejection listeners added. Use emitter.setMaxListeners() to increase limit
|
8
|
-
|
9
4
|
イベントハンドラの数を変更すればいいと思ったのですが、
|
10
5
|
なにも変化がなかったので解決策が知りたいです。
|
11
6
|
|
@@ -73,95 +68,4 @@
|
|
73
68
|
end
|
74
69
|
MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 unhandledRejection listeners added. Use emitter.setMaxListeners() to increase limit
|
75
70
|
end
|
76
|
-
end
|
71
|
+
end
|
77
|
-
|
78
|
-
MaxListeners()の上限を増やすか、
|
79
|
-
上限をなくすことで警告が消えると考えているので、
|
80
|
-
その方法を教えていただきたいです。
|
81
|
-
|
82
|
-
環境は以下の通りです。
|
83
|
-
windows10
|
84
|
-
node 7.6.0
|
85
|
-
|
86
|
-
------- 追記です。
|
87
|
-
|
88
|
-
```typescript
|
89
|
-
// main.ts
|
90
|
-
import { fork } from "child_process";
|
91
|
-
const R = require("rambd");
|
92
|
-
|
93
|
-
const work = () => new Promise(resolve=>{
|
94
|
-
const child = fork("pup.ts", [], {
|
95
|
-
cwd : __dirname,
|
96
|
-
env : process.env,
|
97
|
-
})
|
98
|
-
|
99
|
-
child.on("message", result => {
|
100
|
-
return resolve(result)
|
101
|
-
})
|
102
|
-
})
|
103
|
-
|
104
|
-
const fn = async () => {
|
105
|
-
const promised = R.range(0, 12).map(() => work())
|
106
|
-
const result = await Promise.all(promised)
|
107
|
-
|
108
|
-
console.log(result, 'DONE')
|
109
|
-
}
|
110
|
-
|
111
|
-
fn()
|
112
|
-
})
|
113
|
-
```
|
114
|
-
```typescript
|
115
|
-
// pup.ts
|
116
|
-
const assert = require('assert');
|
117
|
-
const puppeteer = require('puppeteer');
|
118
|
-
|
119
|
-
const work = async () => {
|
120
|
-
process.on('unhandledRejection', console.dir);
|
121
|
-
const browser = await puppeteer.launch();
|
122
|
-
const page = await browser.newPage();
|
123
|
-
|
124
|
-
await page.goto('http://~~', {waitUntil: 'networkidle2'});
|
125
|
-
|
126
|
-
await page.focus('input[name="username"]');
|
127
|
-
await page.type('xxxxx');
|
128
|
-
await page.focus('input[name="password"]');
|
129
|
-
await page.type('yyyyy');
|
130
|
-
const buttonElement = await page.$('button[type=submit]');
|
131
|
-
await buttonElement.click();
|
132
|
-
await page.waitFor(5000);
|
133
|
-
|
134
|
-
const selecterResult = await page.evaluate(() => {
|
135
|
-
const node = document.body.querySelector('span');
|
136
|
-
return node.tagName;
|
137
|
-
});
|
138
|
-
|
139
|
-
await browser.close();
|
140
|
-
return 'end';
|
141
|
-
}
|
142
|
-
|
143
|
-
work()
|
144
|
-
.then(result => {
|
145
|
-
process.send(result)
|
146
|
-
process.exit()
|
147
|
-
})
|
148
|
-
```
|
149
|
-
|
150
|
-
結果は以下の通りです。
|
151
|
-
> module.js:472
|
152
|
-
throw err;
|
153
|
-
^
|
154
|
-
Error: Cannot find module 'rambda'
|
155
|
-
at Function.Module._resolveFilename (module.js:470:15)
|
156
|
-
at Function.Module._load (module.js:418:25)
|
157
|
-
at Module.require (module.js:498:17)
|
158
|
-
at require (internal/module.js:20:19)
|
159
|
-
at Object.<anonymous> (path:4:11)
|
160
|
-
at Module._compile (module.js:571:32)
|
161
|
-
at Object.Module._extensions..js (module.js:580:10)
|
162
|
-
at Module.load (module.js:488:32)
|
163
|
-
at tryModuleLoad (module.js:447:12)
|
164
|
-
at Function.Module._load (module.js:439:3)
|
165
|
-
|
166
|
-
rambdaを利用していないので当然といえば当然ですが、
|
167
|
-
使わないと実装できないのでしょうか?
|
1
参考リンクを元に実装、結果
title
CHANGED
File without changes
|
body
CHANGED
@@ -81,4 +81,87 @@
|
|
81
81
|
|
82
82
|
環境は以下の通りです。
|
83
83
|
windows10
|
84
|
-
node 7.6.0
|
84
|
+
node 7.6.0
|
85
|
+
|
86
|
+
------- 追記です。
|
87
|
+
|
88
|
+
```typescript
|
89
|
+
// main.ts
|
90
|
+
import { fork } from "child_process";
|
91
|
+
const R = require("rambd");
|
92
|
+
|
93
|
+
const work = () => new Promise(resolve=>{
|
94
|
+
const child = fork("pup.ts", [], {
|
95
|
+
cwd : __dirname,
|
96
|
+
env : process.env,
|
97
|
+
})
|
98
|
+
|
99
|
+
child.on("message", result => {
|
100
|
+
return resolve(result)
|
101
|
+
})
|
102
|
+
})
|
103
|
+
|
104
|
+
const fn = async () => {
|
105
|
+
const promised = R.range(0, 12).map(() => work())
|
106
|
+
const result = await Promise.all(promised)
|
107
|
+
|
108
|
+
console.log(result, 'DONE')
|
109
|
+
}
|
110
|
+
|
111
|
+
fn()
|
112
|
+
})
|
113
|
+
```
|
114
|
+
```typescript
|
115
|
+
// pup.ts
|
116
|
+
const assert = require('assert');
|
117
|
+
const puppeteer = require('puppeteer');
|
118
|
+
|
119
|
+
const work = async () => {
|
120
|
+
process.on('unhandledRejection', console.dir);
|
121
|
+
const browser = await puppeteer.launch();
|
122
|
+
const page = await browser.newPage();
|
123
|
+
|
124
|
+
await page.goto('http://~~', {waitUntil: 'networkidle2'});
|
125
|
+
|
126
|
+
await page.focus('input[name="username"]');
|
127
|
+
await page.type('xxxxx');
|
128
|
+
await page.focus('input[name="password"]');
|
129
|
+
await page.type('yyyyy');
|
130
|
+
const buttonElement = await page.$('button[type=submit]');
|
131
|
+
await buttonElement.click();
|
132
|
+
await page.waitFor(5000);
|
133
|
+
|
134
|
+
const selecterResult = await page.evaluate(() => {
|
135
|
+
const node = document.body.querySelector('span');
|
136
|
+
return node.tagName;
|
137
|
+
});
|
138
|
+
|
139
|
+
await browser.close();
|
140
|
+
return 'end';
|
141
|
+
}
|
142
|
+
|
143
|
+
work()
|
144
|
+
.then(result => {
|
145
|
+
process.send(result)
|
146
|
+
process.exit()
|
147
|
+
})
|
148
|
+
```
|
149
|
+
|
150
|
+
結果は以下の通りです。
|
151
|
+
> module.js:472
|
152
|
+
throw err;
|
153
|
+
^
|
154
|
+
Error: Cannot find module 'rambda'
|
155
|
+
at Function.Module._resolveFilename (module.js:470:15)
|
156
|
+
at Function.Module._load (module.js:418:25)
|
157
|
+
at Module.require (module.js:498:17)
|
158
|
+
at require (internal/module.js:20:19)
|
159
|
+
at Object.<anonymous> (path:4:11)
|
160
|
+
at Module._compile (module.js:571:32)
|
161
|
+
at Object.Module._extensions..js (module.js:580:10)
|
162
|
+
at Module.load (module.js:488:32)
|
163
|
+
at tryModuleLoad (module.js:447:12)
|
164
|
+
at Function.Module._load (module.js:439:3)
|
165
|
+
|
166
|
+
rambdaを利用していないので当然といえば当然ですが、
|
167
|
+
使わないと実装できないのでしょうか?
|