-
Notifications
You must be signed in to change notification settings - Fork 62
/
complexity.ts
43 lines (37 loc) · 1.13 KB
/
complexity.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import * as instamancer from "instamancer";
import {Response} from "puppeteer";
class Complexity<PostType> implements instamancer.IPlugin<PostType> {
private query: string;
constructor(query: string) {
this.query = query;
}
public async responseEvent(
this: instamancer.IPluginContext<Complexity<PostType>, PostType>,
res: Response,
data: {[key: string]: any},
): Promise<void> {
const elementCount = await this.state.page.evaluate((query) => {
return document.querySelectorAll(query).length;
}, this.plugin.query);
process.stdout.write(
`${this.plugin.query} elements: ${elementCount}\n`,
);
}
}
const user = instamancer.createApi("user", "therock", {
enableGrafting: false,
plugins: [
new Complexity("div"),
new Complexity("span"),
new Complexity("img"),
],
silent: true,
total: 500,
});
(async () => {
const posts: instamancer.TPost[] = [];
for await (const post of user.generator()) {
posts.push(post);
}
process.stdout.write(`Total posts ${posts.length}`);
})();