I use this code to change the href attribute of an HTML stream.
I first load the full html page using this code: (webpage url)
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(URL);
HttpWebResponse myHttpWebResponse =
(HttpWebResponse)myHttpWebRequest.GetResponse();
Stream s = myHttpWebResponse.GetResponseStream();
then I process this:
HtmlDocument doc = new HtmlDocument();
doc.Load(s);
foreach (HtmlNode link in doc.DocumentNode.SelectNodes("/a"))
{
string att = link.Attributes["href"].Value;
link.Attributes["href"].Value = "http://ahmadalli.somee.com/default.aspx?url=" + att;
}
doc.Save(s);
s - html stream.
but I have an exception that says it doc.DocumentNodeis null!
I have tried many sites but doc.DocumentNodenull for
source
share