const puppeteer = require('puppeteer-extra') const pluginStealth = require('puppeteer-extra-plugin-stealth') puppeteer.use(pluginStealth()) async function main() { const browser = await puppeteer.launch({ headless: false, defaultViewport: null, executablePath: 'C:\\c-dev\\chrome.exe' }) const [page] = await browser.pages() await page.goto('https://www.monotaro.id/s000009132.html', {timeout: 0, waitUntil: 'domcontentloaded'}) await page.waitForSelector('#product-attribute-specs-table', {timeout: 0}) const berat = await page.evaluate(() => { let b = 0 const selector_head = '#product-attribute-specs-table tbody tr:nth-child({}) th' const selector_body = '#product-attribute-specs-table tbody tr:nth-child({}) td' let i = 1 document.querySelectorAll('#product-attribute-specs-table tbody tr').forEach(el => { const data = { name: document.querySelector(selector_head.replace('{}', i)).innerText, value: document.querySelector(selector_body.replace('{}', i)).innerText } if(data.name == 'Berat (Kg)') b = data.value.match(/^[0-9]*\.?[0-9]*$/)[0] i+=1 }) return b }) console.log(berat) } main()
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter