8oris
8oris

Reputation: 461

Issue by listing specific selectors and get href

I'm new to javascript and using puppeteer, i'd like to get all the podcast url from this url https://www.lesonunique.com/podcasts

Here's my code:

const puppeteer = require("puppeteer")

const getList = async () => {
  const browser = await puppeteer.launch({ headless: false, args: [ '--proxy-server=firewall.ina.fr:81' ] })
  const page = await browser.newPage()
  await page.goto("https://www.lesonunique.com/podcasts")
  await page.waitForSelector('div.block3-content.block3-content-modif')
  const urls = await page.evaluate(() => Array.from(
      document.querySelectorAll('div.block3-content.block3-content-modif'),
      link => link.href
    ));
  console.log(urls);
  console.log(urls[1]);

The result of console.log(urls) is a 3x3 matric of NULL valuess.

What did i did wrong?

Upvotes: 0

Views: 33

Answers (1)

8oris
8oris

Reputation: 461

I found the correct way to do it:

  const elements = await page_podcast_list.$$eval('div.block3-content.block3-content-modif', podcasts => {
    return podcasts.map(podcast => podcast.getElementsByTagName('a')[0].getAttribute('href'));
    });
  console.log(typeof(elements));
  console.log(elements);

Upvotes: 1

Related Questions