1

I have made a web scraping script in Node JS using Puppeteer and Cheerio. It works alright so far, but my issue now is that is want to be able to interact (click) with an element that i have found with cheerio.

I have tried extracting the xpath and other issues, but it did not seem to work.

I have tried returning the entire query selector but with no luck. When i try to use the same syntax from cheerio into a single query selector using puppeteer it fails....


puppeteer.launch({headless: false})
.then(async (browser) =>{
  let page = await browser.newPage();
  page.goto(providerUrl)
  .then(async () =>{
    const content = page.content();
    content.then(success =>{
      const $ = cheerio.load(success);
      const wrapperChildren = $('.providerCardOut > div').children()
      wrapperChildren.each(async (index, elem) =>{
        //how to click this element, when it is found. 
        const clickableButton = $(elem).find('.providerCard-spoiler-title providerCard-closed')
    })
  })
})
ggorlen
  • 44,755
  • 7
  • 76
  • 106
Kristoffer Tølbøll
  • 3,157
  • 5
  • 34
  • 69
  • If you need to click something, why not use Puppeteer to find the element and click it? I don't see why Cheerio is needed. If the selector isn't working with Puppeteer, please show the relevant website/HTML/JS so I can reproduce the problem. – ggorlen Jan 07 '21 at 21:44
  • That won't work but you can use jquery in the browser context which is similar. – pguardiario Jan 08 '21 at 00:21
  • See [Pass Cheerio element to Puppeteer to have it clicked](https://stackoverflow.com/questions/64928487/pass-cheerio-element-to-puppeteer-to-have-it-clicked) – ggorlen Jan 04 '23 at 19:51

0 Answers0