"use strict"; const surgeon = require("../../shared/surgeon-utils"); // https://uk.farnell.com/molex/51281-2694/fpc-connector-rcpt-26pos-0-3mm/dp/3051223 module.exports = function farnellScrapeProduct({ gotSession }) { return async function ({ data, updateData, expireDependents }) { let response = await gotSession(data.url, { timeout: 30000 }); let detailsTable = surgeon(`selectOne ".productDescription dl" | extractDefinitionList`, response.body); let itemData = surgeon({ datasheetURL: [ () => detailsTable, `maybeCell "Technical Datasheet:" | selectOne a | readAttr href` ], manufacturer: `selectOne .schemaOrg | text`, model: `selectOne .ManufacturerPartNumber | text`, productID: `selectOne .ManufacturerOrderCode | text`, description: `selectOne .pdpAttributesName | text`, alsoKnownAs: [ () => detailsTable, `maybeCell "Also Known As:" | text` ] }, response.body); // TODO: Merge self into productID-normalized item to deal gracefully with changing URLs updateData((oldData) => ({ ... oldData, itemData: itemData })); expireDependents(); }; };