Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6002253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:57:05+00:00 2026-05-23T00:57:05+00:00

I want to get the A href of that element in span class=floatClear whose

  • 0

I want to get the A href of that element in span class=”floatClear” whose rating is minimum in
span class=”star-img stars_4″

How can I use HtmlAgilityPack to achieve this behaviour I have give the html source of my file

<div class="businessresult">  //will repeat


      <div class="rightcol">

       <div class="rating">

        <span class="star-img stars_4">
          <img height="325" width="84" src="http://media1.px" alt="4.0 star rating"   **title**="4.0 star rating">
         </span>

        </div>
      </div>

        <span class="floatClear">
             <a class="ybtn btn-y-s" href="/writeareview/biz/KaBw8UEm8u6war_loc%NY">
        </span>
</div>

The query I have written

var lowestreview = 
      from main in htmlDoc.DocumentNode.SelectNodes("//div[@class='rightcol']") 
       from rating in htmlDoc.DocumentNode.SelectNodes("//div[@class='rating']")
         from ratingspan in htmlDoc.DocumentNode.SelectNodes("//span[@class='star-img stars_4']")
          from floatClear in htmlDoc.DocumentNode.SelectNodes("//span[@class='floatClear']")
       select new { Rate = ratingspan.InnerText, AHref = floatClear.InnerHtml };

But I do not know how to apply condition here at last line of LINQ query!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T00:57:06+00:00Added an answer on May 23, 2026 at 12:57 am

    Don’t select “rating” from the entire htmlDoc, select it from the previously found “main”.

    I guess you need something like:

    var lowestreview = 
      from main in htmlDoc.DocumentNode.SelectNodes("//div[@class='rightcol']") 
       from rating in main.SelectNodes("//div[@class='rating']")
         from ratingspan in rating.SelectNodes("//span[@class='star-img stars_4']")
          from floatClear in ratingspan.SelectNodes("//span[@class='floatClear']")
       select new { Rate = ratingspan.InnerText, AHref = floatClear.InnerHtml };
    

    I hope it will not crash if some of those divs ans spans are not present: a previous version of the HtmlAgilityPack returned null instead of an empty list when the SelectNodes didn’t find anything.

    EDIT
    You probably also need to change the “xpath query” for the inner selects: change the “//” into “.//” (extra . at the beginning) to signal that you really want a subnode. If the AgilityPack works the same as regular XML-XPath (I’m not 100% sure) then a “//” at the beginning will search from the root of the document, even if you specify it from a subnode. A “.//” will always search from the node you are searching from.

    A main.SelectNodes("//div[@class='rating']") will (probably) also find <div class="rating">s outside the <div class="rightcol"> you found in the previous line.
    A main.SelectNodes(".//div[@class='rating']") should fix that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to get an element by its href attribute in jquery or javascript.
I want to get an overview of files that are updated in TFS (that
I want to get user input in one page, store that in a php
I want to get a type of a BasePage object that I am creating.
I want to get started doing some game development using Microsoft's XNA. Part of
I want to get the MD5 Hash of a string value in SQL Server
I want to get my databases under version control. I'll always want to have
I want to get the base 10 logarithm of a Fixnum using Ruby, but
I want to get a files these attributes as integer values.
I want to get the size of an http:/.../file before I download it. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.