代码之家  ›  专栏  ›  技术社区  ›  punkish

使用cheerio选择嵌套节点

  •  0
  • punkish  · 技术社区  · 6 年前

    更新: 我想出来了。请参阅下面的答案

    我有一个这样的xml,我想选择 a[type="foo"] d . 我正在使用 cheerio . 我已经到了 d = $('a[type=foo]')

    <a type="foo">
        <b>
            <c>
                <d blah="fop" bung="frum">
                    <e>Lorem Dramam</e>
                </d>
                <f>sp. cr.</f>
            </c>
        </b>
        <b box="[4,7,18,22]" from="31" to="32">
            urn:foo:bar:baz
            <g box="[2,9,10,12]" code="AC" from="31" to="32">AC</g>
            crummy 
            <h box="[7,12,22,30]" country="Nigeria">A</h>
            winter
        </b>
    </a>
    

    回答: const d = $('a[type=foo] d')

    1 回复  |  直到 6 年前
        1
  •  0
  •   punkish    6 年前

    遵循jQuery选择范式, const d = $('a[type=foo] d') 做这个工作