Closed3
Puppeteer備忘録
[複数要素を取得後にループして子要素のテキストを取得する方法]
<div class="product_title">
<a href="#">リンクテキスト1</a>
</div>
<div class="product_title">
<a href="#">リンクテキスト2</a>
</div>
const product_list = await page.$$('.product_title');
for (const product_el of product_list) {
let product_name = await (await product_el.$('a').getProperty('textContent')).jsonValue()
consolue.log(product_name);
}
//リンクテキスト1
//リンクテキスト2
#非表示以外の要素を指定して取得する方法
const active_option = await page.$('#ProductSelect-product-template option:not([disabled])');
radioなどの複数要素をすべてクリックする方法
await page.evaluate(() => {
//複数要素であっても下記で対応できる
const els = document.querySelectorAll('.formLabel input[type="radio"]');
for (const el of els) {
el.click();
}
});
このスクラップは2ヶ月前にクローズされました
作成者以外のコメントは許可されていません