Click here to Skip to main content
15,920,576 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am new to the HtmlUtilityPack and am finding it very difficult to get at some data. Could someone please explain how I would capture these values from the html given below:

In "span itemprop='sku'", the number: 791-5971
In "span itemprop='name'", the string: Duracell
In "span itemprop='mpn'", the number: 5000394002906

Thank you.

XML
<div class="keyDetailsDivLL">
    <ul class="keyDetailsLL">
        <li>
            <span class="keyLabel">Stock No.</span>
            <span itemprop="sku" class="keyValue bold">791-5971</span>
        </li>
        <li>
            <span class="keyLabel">Brand</span>
            <span class="keyValue"><span itemprop='brand' itemscope='' itemtype='http://schema.org/Organization'>
                                <a href="/web/b/duracell/" alt="Duracell" title="Buy Duracell products online"><span itemprop='name'>Duracell</span></a></span>
            </span>
        </li>
            <li>
                <span class="keyLabel">Mfr. Part No.</span>
                <span class="keyValue bold"><span itemprop='mpn'>5000394002906</span></span>
            </li>
    </ul>

</div>
Posted

you can do as below

C#
string skuval = htmlDoc.DocumentNode.SelectSingleNode("//span[@itemprop='sku']").InnerText;
string nameval = htmlDoc.DocumentNode.SelectSingleNode("//span[@itemprop='name']").InnerText;
string mpnval = htmlDoc.DocumentNode.SelectSingleNode("//span[@itemprop='mpn']").InnerText;
 
Share this answer
 
v2
As is often the case, the process of phrasing the question led me to discover a solution:

HtmlNode spc = document.DocumentNode.SelectSingleNode("//span[@itemprop='sku']");

HtmlNode manufacturer = document.DocumentNode.SelectSingleNode("//span[@itemprop='name']");

HtmlNode mpn = document.DocumentNode.SelectSingleNode("//span[@itemprop='mpn']");


However, I would still be interested in alternatives.

Thanks again.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900