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 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: To learn more see the MSDN article or several other tutorials. [@ id = 'main']
). You need to apply a filter to the collection of nodes like div
or *
.
// "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);
Comments
Post a Comment