-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuserParser.js
57 lines (48 loc) · 1.46 KB
/
userParser.js
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import makeRequest from './makeRequest.js';
import { randDelay } from './delay.js';
import { domain, language, smallDelay } from './globals.js'
class User {
constructor() {
this.id;
this.profileUrl;
this.name;
this.affiliations = [];
this.emailDomain;
this.interests = [];
}
}
export default class UserParser {
constructor() {
this.document = null;
this.user = new User();
this.contentsNodeList = null;
this.notFoundMsg = '<Value not found.>';
}
async parseUserProfile(userId) {
try {
let userProfileUrl = `${domain}/citations?user=${userId}&hl=${language}`;
await randDelay(...smallDelay);
this.document = await makeRequest(userProfileUrl);
this.user.id = userId;
this.user.profileUrl = userProfileUrl;
let userData = this.document.querySelectorAll('div[role="main"]')[1].children[0].lastChild.children;
this.user.name = userData[0].textContent;
this.user.affiliations = userData[1].textContent.split(', ');
this.user.emailDomain = userData[2].textContent.match(/at (.*)\s?-?/)[1];
for (let interest of userData[3].children) {
this.user.interests.push(interest.textContent);
}
} catch (error) {
console.error('Error while parsing article at ' + articleUrl, error);
return Promise.reject(error);
}
}
reset() {
this.user = new User();
}
getProfile() {
let profile = this.user;
this.reset();
return profile;
}
}