Cheerio: How to select element by text content?

前端 未结 2 782
-上瘾入骨i
-上瘾入骨i 2021-02-05 07:29

I have some HTML like this:

Code: 12345
Category: faucets         


        
2条回答
  •  南旧
    南旧 (楼主)
    2021-02-05 08:12

    A simpler solution is:

    var category = $('span:contains("Category:") + span').text()
    

    This is css plus the :contains pseudo that is part of jQuery and supported by cheerio.

提交回复
热议问题