简体   繁体   中英

Does anyone know how to grab this specific value using cheerio (node.js)?

<input type="hidden" name="form_build_id" id="form-ID-numbers" value="form-value-numbers" />

I'm trying to grab the following using cheerio. However, I keep getting undefined. I want to include the name because there are other input tags as well, but I want to grab this specific one. The name is unique. Thanks for the help :)

I tried using the following and it keeps giving me 'undefined':

$('input[name="form_build_id"]').val();

When I go to that URL and then do a View/Source (which should give me the same HTML that cheerio will get), there is only one form and there is no element like what you're looking for in it. So, that's likely why your cheerio code can't get it - it isn't there.

Assuming you are seeing the right data in your View/Source and since it appears you're looking for info from a view/cart page, you would have to have the right login cookie in order to have access to the right data. So, if you're seeing the target form element when you do View/Source in your browser, then the issue would be that you don't have the right login cookie being sent with your node.js request.

You will need to get the right login cookie to send with your nodejs request. That means either logging in via nodejs and capturing that cookie (perhaps with a cookie jar) or somehow manually grabbing the cookie and then including it with your request.

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