Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Trying to add HtmlAgilityPack, run into number of errors

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Trying to add HtmlAgilityPack, run into number of errors

    Hi,

    I have been using HtmlAgilityPack with NT7 some years ago, and later migrated it to the early versions of NT8. I tried adding HtmlAgilityPack (added the dll&xml, and added reference) to my NT8 project, which raised a list of errors. See attached file error-without-netstandard.csv

    I then added netstandard (added the dll&xml, and added reference), and then got even more error. See attached file error-with-netstandard.csv

    Could you help please?



    Attached Files

    #2
    Hello Shai Samuel,

    You would need to find a .net framework version of that library, not the .net standard version. NinjaScript in NT8 is C# 4.8 .net framework. If there is only a .net standard version I would not suggest using that library with NinjaTrader.

    JesseNinjaTrader Customer Service

    Comment


      #3
      Thank you for the kind reply Jesse. It appears there is no .net framework version of it, as the future of .net framework is not clear.

      Anyway, I am looking for a xml and html parser. HtmlAgilityPack and XPath allowed me to do both, including extracting data from webpage, for example, reading the expected news hours from fire factory.com. Could you please suggest alternative libraries, that will work well with NT8?

      Comment


        #4
        Hello Shai Samuel,

        This would be a situation where you need to use a search engine to find and compare libraries based on what features you need. I am not familiar with any specific library for the tasks you mentioned. The requirement for the library to work with NinjaScript would be that it needs to be a .net framework library and equal to or less than 4.8 version.

        If that is an open source library you could look at extracting the relevant C# code for what you needed out of that library and then placing that code inside the NinjaScript addons folder. If the library targets another framework like .netstandard or uses newer C# features you will likely need to do some code changes/error correction to get that code to compile. You would also need to reference any needed C# libraries which the types in that code references.

        Another item would be to research if any of the web pages which you want to extract data from have an API, if so you could just do a web request or use whatever means their API is configured to use. A lot of web sites offer public API's when providing data is involved so that would generally be the suggested route for getting external data from a source if available.



        JesseNinjaTrader Customer Service

        Comment


          #5
          This worked for me. Simple...
          Download the source from github - url below
          Load the solution (.sln) file in visual studio
          Right click on the version and build (3.5 & 4.5 both worked fine)
          Move the resulting dll to the Ninjatrader custom folder
          Add the reference
          Run the code.


          Code:
          using HtmlAgilityPack;
          
                 string Rsp = Fun.GetUrlSynchronous("https://SomePageWithTables.htm") ;
                  HtmlDocument doc = new HtmlDocument();
                  doc.LoadHtml(Rsp);
                  foreach (HtmlNode table in doc.DocumentNode.SelectNodes("//table"))
                  {
                     Print("Found: " + table.Id);
                      foreach (HtmlNode row in table.SelectNodes("tr"))
                      {
                          Print("row " + row.Id);
                          foreach (HtmlNode cell in row.SelectNodes("th|td"))
                          {
                              Print("cell: " + cell.InnerText);
                          }
                      }
                  }
              
          
               public static string GetUrlSynchronous(string url)
                  {
                      HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
                      HttpWebResponse resp = (HttpWebResponse)req.GetResponse(); //Synchronous request
          
                      StreamReader sr = new StreamReader(resp.GetResponseStream());
                      string results = sr.ReadToEnd();
                      sr.Close();
          
                      return results;
                  }​
          ​


          Download the library here FIXED: Performance optimization with Avoid creating new strings when parsing PcData #541 FIXED: The html rendering result is different from the html output result when we...
          Attached Files
          Last edited by Bidder; 04-27-2024, 12:20 AM.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by AdamDJ8, Today, 09:18 PM
          0 responses
          2 views
          0 likes
          Last Post AdamDJ8
          by AdamDJ8
           
          Started by knowmad, Today, 03:52 AM
          2 responses
          26 views
          0 likes
          Last Post knowmad
          by knowmad
           
          Started by ETFVoyageur, Today, 07:05 PM
          0 responses
          9 views
          0 likes
          Last Post ETFVoyageur  
          Started by Orion815, 05-02-2024, 08:39 AM
          2 responses
          18 views
          0 likes
          Last Post Orion815  
          Started by suroot, 02-25-2017, 04:43 AM
          11 responses
          2,554 views
          0 likes
          Last Post Zilvercat  
          Working...
          X