first commit
This commit is contained in:
parent
921cfa389c
commit
a554020123
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
node_modules
|
||||
vars.js
|
1
.idea/.name
Normal file
1
.idea/.name
Normal file
|
@ -0,0 +1 @@
|
|||
index.js
|
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/sisa_crawl.iml" filepath="$PROJECT_DIR$/.idea/sisa_crawl.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
67
evaluateStartPakket.js
Normal file
67
evaluateStartPakket.js
Normal file
|
@ -0,0 +1,67 @@
|
|||
const IFRAME_SELECTOR = 'iframe[title="Hoofdinhoud"]';
|
||||
const CELL_SELECTOR = 'a[title="Sectie uitvouwen Algemene opleidingsonderdelen"]';
|
||||
|
||||
|
||||
/**
|
||||
* Extracted function to get the text content of a node.
|
||||
* @param {ElementHandle} node - The node to get the text content from.
|
||||
* @returns {Promise<string>} The text content of the node.
|
||||
*/
|
||||
async function getNodeTextContent(node) {
|
||||
return await node.evaluate(node => node.textContent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracted function to retrieve the content frame.
|
||||
* @param {Page} page - The Puppeteer page object.
|
||||
* @returns {Promise<Frame>} The content frame.
|
||||
*/
|
||||
async function getContentFrame(page) {
|
||||
await page.waitForSelector(IFRAME_SELECTOR);
|
||||
const iframe = await page.$(IFRAME_SELECTOR);
|
||||
if (!iframe) {
|
||||
throw new Error('Could not find iframe on the AA-page');
|
||||
}
|
||||
console.log('iframe found on AA-page')
|
||||
return await iframe.contentFrame();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the 'Startpakket' is available by verifying text content in a cell
|
||||
* and the `aria-expanded` attribute.
|
||||
*
|
||||
* @param {Page} page - The Puppeteer page object.
|
||||
* @returns {Promise<boolean>} True if the 'Startpakket' is available, false otherwise.
|
||||
*/
|
||||
async function isStartPakketAvailable(page) {
|
||||
const contentFrame = await getContentFrame(page);
|
||||
await contentFrame.waitForSelector(CELL_SELECTOR);
|
||||
const cell = await contentFrame.$(CELL_SELECTOR);
|
||||
console.log(cell);
|
||||
|
||||
if (!cell) {
|
||||
console.error('Cell not found');
|
||||
return false;
|
||||
}
|
||||
|
||||
const isCollapsed = await isAriaExpandedFalse(cell);
|
||||
|
||||
console.log(`Aria-expanded: ${isCollapsed}`);
|
||||
|
||||
return isCollapsed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given cell node has an `aria-expanded` attribute with a value of 'false'.
|
||||
*
|
||||
* @param {ElementHandle} node - The node to check the `aria-expanded` attribute.
|
||||
* @returns {Promise<boolean>} True if the `aria-expanded` attribute is 'false', false otherwise.
|
||||
*/
|
||||
async function isAriaExpandedFalse(node) {
|
||||
if (!node) {
|
||||
throw new Error('Node is not defined');
|
||||
}
|
||||
return await node.evaluate(element => element.getAttribute('aria-expanded') === 'false');
|
||||
}
|
||||
|
||||
module.exports = isStartPakketAvailable ;
|
65
handleDashboardForm.js
Normal file
65
handleDashboardForm.js
Normal file
|
@ -0,0 +1,65 @@
|
|||
const {career, program, academicYear} = require("./vars");
|
||||
|
||||
async function handleDashboardForm(page) {
|
||||
try {
|
||||
const { career, program, academicYear } = require('./vars.js');
|
||||
|
||||
await page.waitForSelector('#QQ_RUNCNTL_OIS_ACAD_CAREER');
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
|
||||
await page.evaluate((career) => {
|
||||
const inputField = document.querySelector('#QQ_RUNCNTL_OIS_ACAD_CAREER'); // Replace with your input field's ID
|
||||
if (inputField) {
|
||||
inputField.value = career;
|
||||
}
|
||||
}, career);
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
await page.keyboard.press("Tab");
|
||||
|
||||
await page.evaluate((program) => {
|
||||
const inputField = document.querySelector('#QQ_RUNCNTL_OIS_ACAD_PROG'); // Replace with your input field's ID
|
||||
if (inputField) {
|
||||
inputField.value = program;
|
||||
}
|
||||
}, program);
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
await page.keyboard.press("Tab");
|
||||
await page.evaluate((academicYear) => {
|
||||
const inputField = document.querySelector('#QQ_RUNCNTL_OIS_STRM'); // Replace with your input field's ID
|
||||
if (inputField) {
|
||||
inputField.value = academicYear;
|
||||
}
|
||||
}, academicYear);
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
await page.keyboard.press("Tab");
|
||||
await page.select('#QQ_RUNCNTL_OIS_QQ_DP_TELLER', '01');
|
||||
|
||||
/* make sure the other fields are cleaned */
|
||||
/* organisatie */
|
||||
await page.evaluate(() => {
|
||||
const inputField = document.querySelector('#QQ_RUNCNTL_OIS_ACAD_ORG'); // Replace with your input field's ID
|
||||
if (inputField) {
|
||||
inputField.value = '';
|
||||
}
|
||||
});
|
||||
|
||||
/* student ID */
|
||||
await page.evaluate(() => {
|
||||
const inputField = document.querySelector('#QQ_RUNCNTL_OIS_EMPLID'); // Replace with your input field's ID
|
||||
if (inputField) {
|
||||
inputField.value = '';
|
||||
}
|
||||
});
|
||||
/* populatie = alle studenten */
|
||||
await page.select('#QQ_RUNCNTL_OIS_QQ_STUD_SELECTOR', 'A');
|
||||
|
||||
/*selectie ophalen*/
|
||||
await page.click("#QQ_RPT_OIS_WRK_QQ_KNOP_FILL_GRID");
|
||||
return page;
|
||||
} catch (error) {
|
||||
console.error("An error occurred:", error);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = handleDashboardForm;
|
90
iterateOverDashboardTable.js
Normal file
90
iterateOverDashboardTable.js
Normal file
|
@ -0,0 +1,90 @@
|
|||
/* TEST MODUS
|
||||
open chrome in debug modus
|
||||
start chrome --remote-debugging-port=9222 --user-data-dir="C:\ChromeDebug"
|
||||
navigeer naar het dashboard en roep de lijst met startpakket studenten op die relevant zijn voor de test
|
||||
start dan het script
|
||||
*/
|
||||
const puppeteer = require("puppeteer");
|
||||
const isStartPakketAvailable = require("./evaluateStartPakket");
|
||||
|
||||
async function iterateOverDashboardTable() {
|
||||
|
||||
/*connection to local host */
|
||||
const browser = await puppeteer.connect({
|
||||
browserURL: 'http://localhost:9222', // Connect to the browser's debugging address
|
||||
});
|
||||
|
||||
// Get all open pages (tabs)
|
||||
const pages = await browser.pages();
|
||||
console.log(`Found ${pages.length} open pages on the browser.`);
|
||||
|
||||
// Interact with the last tab (or any tab of choice)
|
||||
let page = pages[pages.length - 1]; // Choose the last opened tab
|
||||
console.log('Current URL:', page.url());
|
||||
|
||||
// Select the table body by ID
|
||||
const iframeElement = await page.waitForSelector('iframe[title="Hoofdinhoud"]');
|
||||
const iframe = await iframeElement.contentFrame();
|
||||
|
||||
if (!iframe) {
|
||||
console.log('Iframe on dasbhoard inschrijvingen page not found!');
|
||||
return;
|
||||
}
|
||||
|
||||
// Select the table body within the iframe
|
||||
const tableBodySelector = '#QQ_RPT_OIS_TEMP\\$scroll\\$0 tbody';
|
||||
|
||||
// Check if the table exists inside the iframe
|
||||
const tableExists = await iframe.$(tableBodySelector);
|
||||
if (!tableExists) {
|
||||
console.log('Table not found inside iframe!');
|
||||
return;
|
||||
}
|
||||
console.log('Table dashboard found inside iframe!');
|
||||
|
||||
// Get all rows within the table body
|
||||
const links = await iframe.$$(`${tableBodySelector} tr span[title="AA-rapport"] a`);
|
||||
console.log(`Found ${links.length} AA-links to process.`);
|
||||
|
||||
for (let i = 0; i < links.length; i++) {
|
||||
console.log(`Processing link ${i + 1}`);
|
||||
|
||||
const iframeElement = await page.waitForSelector('iframe[title="Hoofdinhoud"]');
|
||||
const iframe = await iframeElement.contentFrame();
|
||||
|
||||
const links = await iframe.$$(`${tableBodySelector} tr span[title="AA-rapport"] a`);
|
||||
|
||||
const [newPagePromise] = await Promise.all([
|
||||
new Promise((resolve) =>
|
||||
browser.once('targetcreated', async (target) => {
|
||||
const newPage = await target.page();
|
||||
resolve(newPage);
|
||||
})
|
||||
),
|
||||
links[i].click(), // Simulate the click
|
||||
]);
|
||||
|
||||
const newPage = await newPagePromise;
|
||||
|
||||
try {
|
||||
const evaluationResult = await isStartPakketAvailable(newPage);
|
||||
|
||||
if (evaluationResult) {
|
||||
console.log(`Evaluation succeeded for link ${i + 1}`);
|
||||
} else {
|
||||
console.log(`Evaluation failed for link ${i + 1}`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Error processing link ${i + 1}:`, error.message);
|
||||
}
|
||||
|
||||
await newPage.close();
|
||||
}
|
||||
|
||||
console.log('All links processed.');
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
module.exports = iterateOverDashboardTable();
|
8
login.js
8
login.js
|
@ -8,19 +8,21 @@ async function runLoginScript(browser) {
|
|||
await page.goto(webpage);
|
||||
|
||||
// Wait for 5 seconds
|
||||
await new Promise((resolve) => setTimeout(resolve, 5000));
|
||||
await page.waitForSelector(".form-control[type=\'email\']");
|
||||
|
||||
// Enter the email
|
||||
await page.type(".form-control[type='email']", email);
|
||||
console.log("email entered");
|
||||
// Wait for 5 seconds
|
||||
await new Promise((resolve) => setTimeout(resolve, 5000));
|
||||
/* await new Promise((resolve) => setTimeout(resolve, 5000)); */
|
||||
|
||||
|
||||
//press enter keyboard
|
||||
await page.keyboard.press("Enter");
|
||||
// Wait for 5 seconds
|
||||
await new Promise((resolve) => setTimeout(resolve, 5000));
|
||||
/*await new Promise((resolve) => setTimeout(resolve, 5000));*/
|
||||
|
||||
await page.waitForSelector(".form-control[type='password']");
|
||||
// Enter the password
|
||||
await page.type(".form-control[type='password']", password);
|
||||
console.log("password entered");
|
||||
|
|
1629
package-lock.json
generated
Normal file
1629
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
4
vars.js
4
vars.js
|
@ -11,6 +11,7 @@ const dasbhoardInschrijvingenURL = 'https://app.sisaweb.uantwerpen.be/psc/csprd_
|
|||
|
||||
const career = 'BACA'
|
||||
const program = 'B0011'
|
||||
const academicYear = '2240'
|
||||
|
||||
|
||||
|
||||
|
@ -22,5 +23,6 @@ module.exports = {
|
|||
runId,
|
||||
dasbhoardInschrijvingenURL,
|
||||
career,
|
||||
program
|
||||
program,
|
||||
academicYear
|
||||
};
|
Loading…
Reference in New Issue
Block a user