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

  • SEARCH
  • Home
  • 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 8425633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:19:32+00:00 2026-06-10T04:19:32+00:00

I am trying to obtain values from a table but am a bit confused

  • 0

I am trying to obtain values from a table but am a bit confused on how to properly do it. I want to retrieve the Strike/Symbol/Bid/Ask from the following page: http://finance.yahoo.com/q/op?s=MSFT&m=2012-09

For my code, I have tried number of things but maybe I am not undrestanding correctly how to utilize Xpath.

private void optionchainButton_Click(object sender, EventArgs e)
        {
            string URL = "http://finance.yahoo.com/q/op?s=" + tickerEditBox.Text;
            string HtmlFile = @".\localfile.html";

            using (WebClient client = new WebClient ()) // WebClient class inherits IDisposable
            {
                client.Proxy = null;
                //client.DownloadFile(URL, @".\localfile.html");
                HtmlWeb hw = new HtmlWeb();
                HtmlAgilityPack.HtmlDocument htmlDoc = hw.Load(URL);
                if (htmlDoc.DocumentNode != null)
                {
                    foreach (HtmlNode text in htmlDoc.DocumentNode.SelectNodes("//table/tbody/tr/td/text()"))
                    {
                        Console.WriteLine(text.InnerText);
                    }
                }

            }

        }
  • 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-06-10T04:19:33+00:00Added an answer on June 10, 2026 at 4:19 am

    For an alternative to HtmlAgilityPack try CsQuery (on nuget as “CsQuery”), you can use CSS selectors and the jQuery API which are may be more familiar and make it easy to do this kind of parsing. Here is how I would do it with CsQuery:

    string URL = "http://finance.yahoo.com/q/op?s=MSFT&m=2012-09";
    
    CQ doc = CQ.CreateFromUrl(URL);
    
    // The two tables have a class "yfnc_datamodoutline1", but wrap an inner table 
    // too.
    // This selector gets the rows of the child table where the actual data lies
    
    var rows = doc.Select(".yfnc_datamodoutline1 table tr");
    
    // Each th header has the class ".yfnc_tablehead1" - figure out which column 
    // to use for the four parts you are interested in by finding the appropriate
    // header column based on the title, and grabbing it's index
    
    var headers = rows.First().Find(".yfnc_tablehead1");
    
    int strikeIndex = headers.Filter(":contains('Strike')").Index();
    int symbolIndex = headers.Filter(":contains('Symbol')").Index();
    int bidIndex = headers.Filter(":contains('Bid')").Index();
    int askIndex = headers.Filter(":contains('Ask')").Index();
    
    // iterate over all rows, except the header one (the "has" excludes the header 
    // row)
    
    foreach (var row in rows.Has("td")) {
        CQ cells = row.Cq().Find("td");
    
        string output = String.Format("Strike: {0} Symbol: {1} Bid: {2} Ask: {3}",
            cells[strikeIndex].Cq().Text(),
            cells[symbolIndex].Cq().Text(),
            cells[bidIndex].Cq().Text(),
            cells[askIndex].Cq().Text());
    
         Console.WriteLine(output);
    }
    

    If you are familiar with CSS & jQuery the methods & selectors should make sense except for the Cq() method in the last loop. This just wraps an element as a CQ object so you can use the jQuery API against it. This is exactly the same as you would do in jQuery with $(row) to wrap a DOM element. That is, when you iterate over a jQuery object, you get actual DOM elements, not more jQuery objects, so if you want to use the jQuery API against each element in a loop, you need to wrap them in jQuery again. This is how you do it in CsQuery. The same loop in jQuery would be coded like:

    rows.Has("td").each(function(i,row) {
        var cells = $(row).find("td"); 
        ..
    });
    

    I have tested this code and it works and returns output like this:

    Strike: 20.00 Symbol: MSFT120922C00020000 Bid: N/A Ask: N/A
    Strike: 21.00 Symbol: MSFT120922C00021000 Bid: N/A Ask: N/A
    Strike: 22.00 Symbol: MSFT120922C00022000 Bid: N/A Ask: N/A
    Strike: 23.00 Symbol: MSFT120922C00023000 Bid: N/A Ask: N/A
    Strike: 24.00 Symbol: MSFT120922C00024000 Bid: N/A Ask: N/A
    Strike: 25.00 Symbol: MSFT120922C00025000 Bid: N/A Ask: N/A
    

    …

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

Sidebar

Related Questions

I am trying to obtain html from the WebBrowser control, but it must include
I am trying to obtain RGB values from an ImagePlus object. I am getting
I'm trying to create a sub-query to obtain the latest date from a table,
I'm trying to display a page in NSIS to obtain two different values. I
OK, I have been trying to obtain the id of a particular link, but
I'm trying to log into a site and obtain the code back, but i'm
In my WP7 project I am trying to obtain data from the GPS device.
I'm trying to parse an OpenOffice spreadsheet to obtain rows with unique values in
I am trying to obtain some information from a webpage that requires login. I
I am trying to obtain the minimum value from a worksheet however when I

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.