-
Notifications
You must be signed in to change notification settings - Fork 0
/
index copy.js
47 lines (27 loc) · 1.11 KB
/
index copy.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
const express = require("express");
const puppeteer = require('puppeteer');
async function scrape(username, problem) {
const url2 = `https://leetcode.com/${username}/`;
const d = new Date(); //start timer
let time1 = d.getTime();
const browser = await puppeteer.launch({ headless: true,args: ['--no-sandbox', '--disable-setuid-sandbox'] });
const page = await browser.newPage();
await page.goto(url2);
let recents = await page.evaluate(() => {
let prob = Array.from(document.body.querySelectorAll("a > div > .text-label-1"), el=> el.innerHTML.toLowerCase().replace(" ","-"));
return prob;
});
browser.close();
const done = recents.indexOf(problem)!=-1
const d1 = new Date(); //end timer
let time2 = d1.getTime();
return Promise.resolve({"done":done, "time":time2-time1, "recents":recents})
}
usernames = ["Mishal0404"]
questions = ["two-sum"]
for (i in usernames){
for (j in questions){
result = scrape(usernames[i], questions[j])
}
}
scrape("Mishal0404", "two-sum").then((e)=>{console.log(e)})