NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

const puppeteer = require('puppeteer');
const fs = require('fs');



class Navigator{
constructor(username, password,type) {
this.username = username
this.password = password
this.login_url = "https://online.bryanuniversity.edu/CMCPortal/secure/student/loginstu.aspx";
this.type=type;
}
async init(){
let browser = await puppeteer.launch({
headless: false
});
let page = await browser.newPage();
page.setViewport({width:1334,height:780})
page=await this.navigate_to_login(page);
page=await this.execute_pre_login(page)
if(!await this.is_login_page(page)){
throw new Error('Not a login page')
}
if(await this.is_login_page(page)){
await this.do_login(page,this.username,this.password)
}
if(await this.is_login_page(page)){
throw new Error('Invald credentials')
}
console.log("Login Succesfull")

if(this.type=="transcript"){
return await this.navigate_to_transcript(page)
}
if(this.type=="profile"){
return await this.navigate_to_profile(page)
}
if(this.type=="grade"){
return await this.navigate_to_grade(page)
}
if(this.type=="dar"){
return await this.navigate_to_dar(page)
}
if(this.type=="multiple_grade"){
return await this.navigate_to_multiple_grade_page(page)
}

}

// Login and PreLogin Steps
async do_login(page,username,password){
console.log('do_login -> started');

await page.waitForSelector(this.elements[0]);
await page.type(this.elements[0], username);

await page.waitForSelector(this.elements[1]);
await page.type(this.elements[1], password);
await page.type(this.elements[1], String.fromCharCode(13));
// string.fromCharCode(13) means after filling value in input press enter
await Promise.race([new Promise(resolve => page.once('load', resolve)), page.waitForTimeout(10000)])

return page;
}
async navigate_to_login(page){
console.log('navigate_to_login -> started');
await page.goto(this.login_url, {
timeout: 20000,
waitUntil: 'load'
});
return page
}
async execute_pre_login(page){
console.log('execute_pre_login -> started');

this.elements = ['input[type="text"]', 'input[type="password"]'];

await page.waitForSelector(this.elements[1],{timeout:20000});

return page;

}
async is_login_page(page){
console.log('is_login_page -> started');

let username_el = await page.evaluate((selector) => {
return document.querySelector(selector);
}, this.elements[0]);

let password_el = await page.evaluate((selector) => {
return document.querySelector(selector);
}, this.elements[1]);

if (username_el || password_el) {
return true;
}
return false;
}


// Post Login Steps
async navigate_to_transcript(page) {
console.log('Navigating to trancript page->>Started')
await page.goto('https://online.bryanuniversity.edu/CMCPortal/Secure/Student/Acad/Transcript.aspx')
await Promise.race([new Promise(resolve => page.once('load', resolve)), page.waitForTimeout(10000)])

return page;
}
async navigate_to_profile(page) {
console.log('Navigating to Profile page->>Started')
await page.waitForSelector("a[href*='/Prof/my_profile']")
await page.click("a[href*='/Prof/my_profile']")
await Promise.race([new Promise(resolve => page.once('load', resolve)), page.waitForTimeout(10000)])
return page;
}
async navigate_to_dar(page) {
console.log('Navigating to dar page->>Started')
await page.goto("https://online.bryanuniversity.edu/CMCPortal/secure/Student/Acad/DegreeAudit.aspx")

await Promise.race([new Promise(resolve => page.once('load', resolve)), page.waitForTimeout(30000)])

return page;
}
async navigate_to_grade(page) {
console.log('Navigating to grade page->>Started')
await page.goto("https://online.bryanuniversity.edu/CMCPortal/secure/Student/Acad/MyGrades.aspx")
const pages=await this.navigate_to_multiple_grades(page)
return pages
}
async navigate_to_multiple_grades(page){
console.log('navigate_to_multiple_grades--> started')
const optionArray = await page.evaluate(() =>
Array.from(document.querySelectorAll('select[id*="lstTerm"] option')).map(element=>element.value));
console.log(optionArray)

const pages=[]

for(let i=0;i<optionArray.length;i++){
await page.select('select#_ctl0_PlaceHolderMain_MyGradesCtrl_lstTerms', optionArray[i])

await page.waitForSelector('span[id*="GradesHeading"]')

await this.store_multiple_grade(page,i)
pages.push(page)
await Promise.race([new Promise(resolve => page.once('load', resolve)), page.waitForTimeout(10000)])



}
// console.log(pages)
return pages
}
async store_multiple_grade(page,i){

// Store Page content
const data = await page.content();
fs.writeFileSync(i+'.html', data);
await Promise.race([new Promise(resolve => page.once('load', resolve)), page.waitForTimeout(10000)])
}



// Close Browser
async close_browser(page) {
await page.close_browser()
}
}
(async () => {
let navObj=new Navigator("abcde","abcedfg","grade")

navObj.init()

})()
     
 
what is notes.io
 

Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 14 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.