简体   繁体   中英

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?

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM