【问题标题】:How do i scrape the value of a element tag with puppeteer我如何用 puppeteer 刮取元素标签的值
【发布时间】:2020-11-29 00:29:11
【问题描述】:
    <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>

我需要使用 puppeteer 刮取“data-automation-id”的值,即“signin-submit-btn”。我知道我可以通过这样做来获取文本

document.querySelector('button[class="button width-full button--primary"]').innerText;

但我需要知道如何获取“data-automation-id”的值

【问题讨论】:

    标签: javascript html jquery web-scraping puppeteer


    【解决方案1】:

    您似乎正在尝试捕获 数据属性 的值。您可以通过引用按钮元素的dataset 来做到这一点,如下所示:

    let mybutton = document.querySelector('button[class="button width-full button--primary"]');
    let autoId = mybutton.dataset.automationId;
    console.log(autoId);
    &lt;button class="button width-full button--primary" data-automation-id="signin-submit-btn" data-tl-id="signin-submit-btn" type="submit"&gt;&lt;span class="button-wrapper"&gt;Sign in&lt;/span&gt;&lt;/button&gt;

    参考这里:https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes

    【讨论】:

      猜你喜欢
      • 2020-08-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-25
      相关资源
      最近更新 更多