是否可以使用Xpath从srcset中找到当前源?

问题描述 投票:0回答:1
html image parsing web-scraping xpath
1个回答
0
投票

看起来

currentSrc
财产为我解决了这个问题。这是完整的工作解决方案:

const getXpathElement = await page.$x(xpath);
const promises = getXpathElement.map((element) => page.evaluate(el => {
                    if (el.currentSrc && (el.tagName && el.tagName.toLowerCase() === "img"))     // when the xpath ends with tag name, Ex: //div//img
                        return el.currentSrc;
                    else            // when the xpath ends with property name, Ex: //div//div/@src
                        return el.textContent
                 }, element));

© www.soinside.com 2019 - 2024. All rights reserved.