简体   繁体   English

使用Cheerio节点在选项中查找特定值

[英]Using Cheerio node to find specific value in option

I am having a hard time picking out the specific number (in this case 7) that is the value of the option. 我很难选择作为选项值的特定数字(在本例中为7)。

heres what im trying: 我在想什么

var $ = cheerio.load(html);
console.log($('ProductSelect').val($("option:contains('7')").val()))

heres html: 继承人的HTML:

<select name="id" id="ProductSelect" class="product-single__variants no-js">


            <option 
                    selected="selected" 
                    data-sku="B42204-Grey Four-7"
                    value="12479371051093">
              7 - <span class=money>$190.00 CAD</span>
            </option>

any ideas on what I can try to be able to properly pin point the value. 关于我可以尝试如何正确指出该值的任何想法。 thanks! 谢谢!

这应该工作:

$('[name="id"] option[selected="selected"]').text().match(/\d+/)[0]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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