Repository navigation
Expand file tree
/
Copy pathResearchGate Scraper.user.js
More file actions
52 lines (45 loc) · 1.94 KB
/
Copy pathResearchGate Scraper.user.js
File metadata and controls
52 lines (45 loc) · 1.94 KB
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
// ==UserScript==
// @name ResearchGate Scraper
// @namespace Violentmonkey Scripts
// @match https://www.researchgate.net/institution/University-of-Barcelona/members/*
// @grant none
// @version 1.0
// @author Your Name
// @description Script to scrape professor data from ResearchGate
// ==/UserScript==
function scrapePage() {
const members = document.querySelectorAll('.nova-legacy-v-person-list-item__body');
let data = JSON.parse(localStorage.getItem('scrapedData')) || [];
for (const member of members) {
const name = member.querySelector('h5').textContent;
const link = "https://www.researchgate.net" + member.querySelector('a').getAttribute('href');
const departmentInfo = member.querySelector('.nova-legacy-v-person-list-item__info-section li');
const department = departmentInfo ? departmentInfo.textContent : '';
const fieldsOfInterest = ["soc", "law", "eco", "human", "polit"];
if (fieldsOfInterest.some(field => department.toLowerCase().includes(field))) {
data.push({
University: 'UB',
Departament: department,
Position: '',
Treatment: '',
Name: name,
Email: '',
Professor_Link: link
});
}
}
localStorage.setItem('scrapedData', JSON.stringify(data));
// Set a random delay of 5 to 10 seconds before navigating to the next page
const randomDelay = Math.random() * 5000 + 5000;
setTimeout(navigateToNextPage, randomDelay);
}
function navigateToNextPage() {
const currentPageNumber = parseInt(window.location.pathname.split('/').pop(), 10);
if (!isNaN(currentPageNumber) && currentPageNumber < 16420) {
const nextPageNumber = currentPageNumber + 1;
const nextPageUrl = `https://www.researchgate.net/institution/University-of-Barcelona/members/${nextPageNumber}`;
window.location.href = nextPageUrl;
}
}
// Wait for the page to load, then run the scrapePage function
window.addEventListener('load', scrapePage);