简体   繁体   中英

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". 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"

It looks like you're trying to capture the value of a Data Attribute . You can do it by referencing the button element's dataset like this:

 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM