admin管理员组文章数量:1400583
I have the below HTML structure
<div class ="container" id= "12">
<div class="details" desc-type= "multiline">
<a href="#">
<div class="description"> Some Description </div>
</a>
</div>
</div>
And I scraping this using the below code
const SELECTOR =
"div.container";
const movies = await page.$$eval(
SELECTOR,
nodes =>
nodes.map(element => {
return {
movieID: element.getAttribute("id"),
};
} )
);
How can I modify the above code so that I can read desc-type= "multiline"
and innerText
of <div class="description">
?
I have the below HTML structure
<div class ="container" id= "12">
<div class="details" desc-type= "multiline">
<a href="#">
<div class="description"> Some Description </div>
</a>
</div>
</div>
And I scraping this using the below code
const SELECTOR =
"div.container";
const movies = await page.$$eval(
SELECTOR,
nodes =>
nodes.map(element => {
return {
movieID: element.getAttribute("id"),
};
} )
);
How can I modify the above code so that I can read desc-type= "multiline"
and innerText
of <div class="description">
?
1 Answer
Reset to default 7How about this?
const movies = await page.$$eval(
SELECTOR,
nodes =>
nodes.map(element => {
return {
movieID: element.getAttribute("id"),
descType: element.querySelector('[desc-type]').getAttribute('desc-type'),
description: element.querySelector(".description").innerText
};
} )
);
本文标签: javascriptAccessing child elements in puppeteerStack Overflow
版权声明:本文标题:javascript - Accessing child elements in puppeteer - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744212971a2595508.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论