-
Notifications
You must be signed in to change notification settings - Fork 0
/
get-bibtex.js
32 lines (26 loc) · 1.02 KB
/
get-bibtex.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
const phantom = require('phantom');
function delay(t, v) {
return new Promise(function(resolve) {
setTimeout(resolve.bind(null, v), t)
});
}
async function getBibtex(start, query, i){
console.log("I am fork", i, start, query);
const pe = await phantom.create();
const page = await pe.createPage();
page.property('viewportSize', { width: 1024, height: 600 });
const status = await page.open(`https://scholar.google.com/scholar?hl=en&q=${query}`);
if(status !== 'success'){
console.log("Could not open the page");
phantom.exit(1);
process.exit(1);
}
page.render(i+".png")
await page.evaluate(function(nth){document.getElementsByClassName("gs-or_cit gs_nph")[nth].click()}, i);
await delay(100).then(()=> page.evaluate(function() {document.querySelector("#gs_citi a:first-child").click()}));
return delay(100).then(()=>page.evaluate(function(){return document.getElementsByTagName("pre")[0].innerHTML}));
}
process.on('message',(m)=> {
getBibtex(m.pagei, m.query, m.i)
.then(txt=> process.send({txt}))
})