stormy-gold
stormy-gold16mo ago

xpath in pageFunction

Is this possible?
3 Replies
absent-sapphire
absent-sapphire16mo ago
Hello @espressodaily, do I understand correctly, that this is related to the "Web Scraper" Actor? If so, you can use the document.evaluate method. For example:
async function pageFunction() {
const headerText = document.evaluate('//h3', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null).snapshotItem(0).textContent;
console.log(`header: ${headerText}`);
return { headerText };
}
async function pageFunction() {
const headerText = document.evaluate('//h3', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null).snapshotItem(0).textContent;
console.log(`header: ${headerText}`);
return { headerText };
}
stormy-gold
stormy-goldOP15mo ago
sorry, yes! thanks for the response. is it possible to pass variables, e.g. item to extract and xpath from api so that it is not hard coded in pageFunction?
Pepa J
Pepa J15mo ago
I am sorry @espressodaily unfortunately I am not sure what you mean exactly, can you give us an example what you try to achieve?

Did you find this page helpful?