C# Null Exception using HTML Agility Pack -


I have a function where I'm trying to get some text from this webpage:

  public static string get_webpage (string url) {HtmlWeb web = new HTML web (); HtmlDocument Doc = web.Load (url); String date = doc.DocumentNode.InnerText; String lotto_winning_numbers = doc.DocumentNode.SelectNodes ("// [@ id = \" main \ "] / div / strong / div / div [2] / div [1] / div [1]"). ToString (); Returned Lotto_Viving_number; }  

When I run the function, I get an exception.

Is my xpath correct? You can not own XPath (like [@ id = 'main']

). You need to apply a filter to the collection of nodes like div or * .

Note that you also want to add value elements to the collection as a result, the collection itself does not have to be converted into a string.

Something like this:

  // "lot" \ "] / Div / strong / div / div [2] / div [1] / div [1]"); // lotto_winning_numbers Here is the collection of nodes. Return Lotto_winning_numbers == Tap? String.opt: ​​string .joined (",", lotto_wiving_number);  

To learn more see the MSDN article or several other tutorials.


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -