Javascript $$eval正在返回未定义的。在pupeteer js中

Javascript $$eval正在返回未定义的。在pupeteer js中,javascript,node.js,puppeteer,Javascript,Node.js,Puppeteer,我目前正在尝试获取一个html文件的img src,但我遇到了一个问题。我不知道该怎么办。让我解释一下: 我在html页面中有几个div: <div class="photo-tile photo-tile-small"><img class="photo-tile-image" src="https://photos.example.com/images/randomimage.jpg"></div> 这将返回“未定义”。我对这一点的理解(我肯定我错了)是

我目前正在尝试获取一个html文件的img src,但我遇到了一个问题。我不知道该怎么办。让我解释一下:

我在html页面中有几个div:

<div class="photo-tile photo-tile-small"><img class="photo-tile-image" src="https://photos.example.com/images/randomimage.jpg"></div>
这将返回“未定义”。我对这一点的理解(我肯定我错了)是在这里吗 $$.eval正在评估名为“.photo tile image”的元素的每个实例,它将返回元素的属性。在这种情况下,它将被称为
img
,从这里我希望它将结果注销到
console.log(getImgSrc)


通过这一点之后,我将如何获得
img.src

传递给
$$eval
的函数的参数不是图像,而是图像数组

因此,从这里开始,您可以:

const getImgSrc=wait page.$$eval('.photo-tile-image',imgs=>imgs.map(img=>img.src));
console.log(getImgSrc);
  const getImgSrc = await page.$$eval('.photo-tile-image', img => img);
  console.log(getImgSrc);