Code: Select all
async function pageFunction(context) {
// This statement works as a breakpoint when you're trying to debug your code. Works only with Run mode: DEVELOPMENT!
// debugger;
// jQuery is handy for finding DOM elements and extracting data from them.
// To use it, make sure to enable the "Inject jQuery" option.
const $ = context.jQuery;
//const pageTitle = $('title').first().text();
//const itemList = $('item-list');
//const body_text_from_the_page = $('p').text();
// Print some information to actor log
//context.log.info(`URL: ${context.request.url}, TITLE: ${pageTitle}`);
//context.log.info(`print item-list, ${itemList}`);
const listings = document.querySelectorAll('.note-item'); // Each listing is within note items
const results = [];
listings.forEach(listing => {
const hrefElement = listing.querySelector('.cover mask ld');
const titleElement = listing.querySelector('.title');
const nameElement = listing.querySelector('.name');
const timeElement = listing.querySelector('.item-location span');
const href = hrefElement ? hrefElement.textContent.trim() : "N/A";
const title = titleElement ? titleElement.textContent.trim() : "N/A";
const name = nameElement ? nameElement.textContent.trim() : "N/A";
const time = timeElement ? timeElement.textContent.trim() : "N/A";
context.log.info('print', title);
results.push({
href,
title,
name,
time
});
});
return results;