Retrieving inner text using HTML Agility Pack

I need assistance with parsing a website I have found here:

https://i.sstatic.net/GdFN1.png

My goal is to extract information from specific fields that have IDs and classnames:

        label =
            node.SelectSingleNode(
                ".//h3[@class='item_header']"
                ).InnerText.Replace("Label: ","").Trim();
        Console.WriteLine(label);

However, I am struggling to retrieve the text contained in tags without any IDs or classes, like in the example below:

https://i.sstatic.net/74Wxf.png

How can I extract the text inside tags that lack identifiers, such as the following?

<b>Label Cat. #: WEST 3007/8</b>

If it helps, here is the unique selector for reference:

#\31 42248 > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > b:nth-child(1)

Answer №1

Did you know that the HTML Agility Pack offers a CSS Selector library that can help you locate specific elements? This library can be a handy tool for web scraping projects.

To explore the CSS Selector library, you can visit the following link: https://www.nuget.org/packages/HtmlAgilityPack.CssSelectors/

Answer №2

If you already have the table's ID, you're good to go.

HtmlNodeCollection elements = doc.DocumentNode.SelectNodes("//table[@id='142248']//b");

foreach (HtmlNode element in elements)
{
    if (element.InnerText.ToLower().Contains("label"))
    {
         Console.WriteLine(element.InnerText);
    }
}

The xpath used in the code above will return all the elements within the table that has the ID 142248.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Enhance the appearance of a dropdown selection using CSS

I am interested in customizing the appearance of the first option (Search Clubs) to be bold, while keeping the rest with normal font weight. Currently, I am able to make the first option bold, but it only appears that way after clicking the dropdown menu ...

Is there a way to enable multiple selections in a particular section?

Currently, I am in the process of working on my step by step order and I want to express my gratitude for all the assistance I have received so far. Despite the help, I still have some unanswered questions! The steps in my project are categorized into dif ...

Getting the location of a mouse click and adding tags (marks) on an image: a simple guide

Is there a way to incorporate images with tagged marks similar to Facebook's image tagging feature? How can I retrieve the X and Y coordinates of tags on the image itself (not the screen) and display them in a responsive manner? ...

Display the contents in a textarea with modal, not as a string

I'm currently working on implementing a modal overlay window with simplemodal that will display the contents of a text area. My goal is to show the rendered output rather than just the string value. For example, if a user enters HTML or includes an im ...

The first pop-up modal in the initial panel will remain closed until the second pop-up modal in the subsequent panel is opened

I have encountered an issue with my setup where I have one updatepanel containing two panels, each with buttons to open popups. The problem arises when clicking on a button in the first panel - the corresponding modalpopup does not open. However, if I clic ...

Unable to swap out image when hovered over

This is a new issue for me, as I can't seem to understand why the hover effect is working, but the background image won't change: <div class="settings" id="settings" style="background-image:url(assets/settings.svg);&qu ...

After a group of floated items, there will be an automatic "clear: both" applied

Within my Content Management System, I have custom Elements that need to be floated next to each other. Instead of adding an extra div with a class of "clear", I want to automatically insert a clear: both at the end using CSS3. I attempted this workaround ...

The z-index property fails to function properly when used with a relative parent and after/before pseudo-elements

Here is the code snippet (prototype) that I am working with: .headerz { position: relative; padding: 5rem 0 0 5rem; margin: 3rem 0 0 0; color: #000; font-size: 3.8rem; text-transform: uppercase; z-index: 24; } .headerz::before { content ...

The EJS is causing a problem with linking the style sheet

Currently, I am in the process of familiarizing myself with ejs, express, and node js. Facing an issue while trying to link my style sheet to my header, below is the code snippet and here is a https://i.stack.imgur.com/0BEIn.png. Utilizing include for bo ...

Is it recommended to add the identical library to multiple iFrames?

Here's a quick question I have. So, my JSP page has 4 different iFrames and I've included JQuery UI libraries in it: <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" /> <script src="http://c ...

The switch statement remains unchanged for varying variables

Here is some code that I am working with: updateTable(selectedIndex) { console.log("running updateTable function"); let level = ''; // if (selectedIndex == 1){ // this.setState({level: 'day'}) // th ...

Use jQuery to assign a unique CSS class to every third ul element on the page

Currently, I have a large number of li elements that I am iterating through and grouping in sets of 5. However, I need to assign a unique class to every third group in order to achieve the following structure: <ul class="class1"> ...

Use TryParseExact or ParseExact in .net to correctly interpret the date and time 2021-03-04T17:00:00.000Z

Could someone assist me in figuring out the pattern needed to match this date time? 2021-03-04T17:00:0s.000Z var dateValue = "2021-03-04T17:00:0s.000Z"; string pattern = "yyyy-MM-dd'T'hh:mm:s's'.fff'Z'"; D ...

The signal property 'ɵunwrapWritableSignal' is not found on the specified type 'typeof import/node_modules/@angular/core/index")'

Despite attempting the solutions provided in previous threads, none of them have been successful for me. Can someone please lend a hand with this issue? https://i.stack.imgur.com/sGRsn.png ...

The functionality of .bind() is malfunctioning on both Microsoft Edge and Google Chrome browsers

Everything seems to be running smoothly on Mozilla (version 103.0), but unfortunately, it's not performing as expected on Chrome or Microsoft Edge. $('#loading').bind('ajaxStart', function () { $(this).show(); }).bind('ajaxS ...

Facilitating seamless authentication between Desktop Application and Website

We are looking for a solution for our client/server application that includes a rich client front end developed in .Net and an administration portal in Asp.Net. Currently, users are required to sign on both the rich client and the website. We want to strea ...

Show only a cropped section of a resized image within a div

I have a script that calculates the best region of an image to display within a specific div size. This calculation is done in PHP and generates a JSON output like this: {"scale":1.34,"x1":502,"x2":822,"y1":178,"y2":578} The image in question has dimensi ...

JQuery's attempt to disable the 'hover' feature fails to function as intended

I have a styled table where rows change background colors based on odd and even indexes, with a hover effect included. However, I want to disable the hover effect when a row is selected. Here's the current code snippet: .odd{ background: #f7f7f7 ...

What other options exist besides global variables, and which alternative is considered the most optimal choice?

What are the potential replacements for global variables, and which option is considered the most effective? I have heard that using global variables is not recommended. Currently, I am developing a WCF application where there may be multiple instances of ...

One helpful tip for adjusting the size of a UI chip on the fly

I am attempting to adjust the size of a UI chip dynamically based on the font size of its parent elements using the em unit in CSS. My objective is to achieve something like this: style={{size:'1em'}} The issue I'm encountering: The chip e ...