[英]How do i scrape the value of a element tag with puppeteer
<button class="button width-full button--primary" data-automation-id="signin-submit-btn" data-tl-id="signin-submit-btn" type="submit"><span class="button-wrapper">Sign in</span></button>
I need to scrape the value of "data-automation-id" with puppeteer which would be "signin-submit-btn".我需要用 puppeteer 刮掉“data-automation-id”的值,这将是“signin-submit-btn”。 I know that I can grab the text by doing this
我知道我可以通过这样做来获取文本
document.querySelector('button[class="button width-full button--primary"]').innerText;
but I need to know how to grab that value of "data-automation-id"但我需要知道如何获取“data-automation-id”的值
It looks like you're trying to capture the value of a Data Attribute .看起来您正在尝试捕获Data Attribute的值。 You can do it by referencing the button element's
dataset
like this:您可以通过引用按钮元素的
dataset
来做到这一点,如下所示:
let mybutton = document.querySelector('button[class="button width-full button--primary"]'); let autoId = mybutton.dataset.automationId; console.log(autoId);
<button class="button width-full button--primary" data-automation-id="signin-submit-btn" data-tl-id="signin-submit-btn" type="submit"><span class="button-wrapper">Sign in</span></button>
Reference here: https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes参考这里: https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.