Skip to content

[WIT] Scrapping class details from jupiter #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion src/user/services/scrapJupiter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const getScrapJupiter = async (nUsp: string, password: string, retry: number = 0
await page.setUserAgent(
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36',
)

await page.goto(loginJupiterLink)

await page.waitForSelector("input[name='codpes']")
Expand Down Expand Up @@ -79,6 +80,7 @@ const getScrapJupiter = async (nUsp: string, password: string, retry: number = 0
const courseId = course!.id
const instituteId = institute!.id

let firstTime = true;
let rowIndex = 1
const hash: any = {}

Expand All @@ -94,7 +96,35 @@ const getScrapJupiter = async (nUsp: string, password: string, retry: number = 0
let subject = await page.evaluate((el: any) => el?.textContent, element)

if (subject) {
subject = subject.split('-')[0]
subject = subject.split('-')[0];

// click on the subject
element = await page.$(`span.${subject}`);
await element?.click();

// wait for the overlay to disappear
await page.waitForSelector('.blockOverlay', { hidden: true });

// treating some bug that makes the first click not work
if (firstTime) {
await element?.click();
await page.waitForSelector('.blockOverlay', { hidden: true });
firstTime = false;
}

// click on the "oferecimento" tab
await page.click('a[href="#div_oferecimento"]');
await page.waitForSelector('.blockOverlay', { hidden: true });

// get the observations and print them
// we could use this to get any detail we want about the subject
let observationsElement = await page.$('div[class="adicionado"] > table > tbody > tr > td[class="obstur"]');
let observationsText = await page.evaluate((el: any) => el?.textContent, observationsElement);
if (observationsText) {
console.log(subject, '- observações:', observationsText);
}

// store data
if (!hash[subject]) {
hash[subject] = [
{
Expand Down