【问题标题】:How to access DOM attributes containing different attribute values using Cheerio?如何使用 Cheerio 访问包含不同属性值的 DOM 属性?
【发布时间】:2019-09-23 05:28:29
【问题描述】:

我正在使用cheerio 抓取nodejs 中的网页。现在我遇到了类似这样结构的网络内容,

<div data-content="123456"> ... </div>
<div data-content="142453"> ... </div>
<div data-content="192638"> ... </div>
<div data-content="152701"> ... </div>
<div data-content="172830"> ... </div>

请注意,data-content 属性具有不同的属性值,并且在 div 中存在我想要删除的必要数据。我如何使用cheerio 来访问这样结构的DOM 属性?

注意:我知道使用div 作为选择器是可能的。但我不想将div 用作cheerio 的选择器。我想专门使用 data-content 作为选择器来访问 DOM 节点。

【问题讨论】:

    标签: jquery-selectors cheerio


    【解决方案1】:

    这应该可行:

    $('div[data-content]')
    

    【讨论】:

      猜你喜欢
      • 2012-12-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-12
      • 1970-01-01
      • 1970-01-01
      • 2020-06-13
      • 2012-07-30
      相关资源
      最近更新 更多