简体   繁体   中英

Parsing a website data c# - HTML agility pack

I tried to parse the results from this website. http://www.nokia.com/in-en/store-locator/?action=storeSearch&qt=madurai&tags=Nokia_Recycling_Point&country=IN

在此输入图像描述

I need specifically the contents of the div class 'result-wrapper'. That is, all the 'h4', 'category' and 'description' span classes. The following is the code I could reach upto, later on, I do not know to parse that particular div. I need help to get all the contents of that div class.

protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            string htmlPage = "";
            using (var client = new HttpClient())
            {
                try
                {
                    htmlPage = await client.GetStringAsync("http://www.nokia.com/in-en/store-locator/?action=storeSearch&qt=madurai&tags=Nokia_Recycling_Point&country=IN");
                }
                catch (HttpRequestException exc) { }
            }

        HtmlDocument htmlDocument = new HtmlDocument();
        htmlDocument.LoadHtml(htmlPage);

Well, you can try:

var resultWrapperDivs = htmlDocument.DocumentNode.SelectNodes("//div[@class='result-wrapper']");
foreach (var resultWrapperDiv in resultWrapperDivs)
{
    // Do stuff with each div.
}

Also, to get a specific content/"html tag" you can take each resultWrapperDiv alone and get also its children nodes ( resultWrapperDiv.SelectSingleNode or resultWrapperDiv.SelectNodes )

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