简体   繁体   中英

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.

heres what im trying:

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

heres 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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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