Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

161
Visualizações
puppeteer click element if the text matches the array

I'm trying to grab products from ebay and open them on amazon. So far, I have them being searched on amazon but I'm struggling with getting the products selected from the search results. Is there a way to select an element based on if the text matches from an array?

Any help greatly appreciated.

const puppeteer = require('puppeteer');
const URL =
  https: //www.amazon.co.uk/";

  const selectors = {
    searchBox: '#twotabsearchtextbox',
    productLinks: `//span[@class="a-size-medium a-color-base a-text-normal"]`,
  };

(async() => {
  const browser = await puppeteer.launch({
    headless: false
  });
  const page = await browser.newPage();
  await page.goto('https://www.ebay.co.uk/sch/jmp_supplies/m.html?_trkparms=folent%3Ajmp_supplies%7Cfolenttp%3A1&LH_Complete=1&LH_Sold=1&rt=nc&_trksid=p2046732.m1684');
  
  //Get product titles from ebay
  const grabTitles = await page.evaluate(() => {
    const itemTitles = document.querySelectorAll('#e1-11 > #ResultSetItems > #ListViewInner > li > .lvtitle > .vip');
    var items = []
    itemTitles.forEach((tag) => {
      items.push(tag.innerText)
    })

    return items
  })

  //Search for the products on amazon in a new tab for each product 
  for (i = 0; i < grabTitles.length; i++) {
    const page = await browser.newPage();
    await page.goto(URL)
    await page.type(selectors.searchBox, grabTitles[i++])
    await page.keyboard.press('Enter');
    await page.waitForXPath(selectors.productLinks);
    const product = await page.$x(selectors.productLinks)
    if (product == grabTitles) {
      await product.click();
    }
  }
})()
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda