Parsing WebResponse with Html Agility Pack

.net c# html-agility-pack

Question

I am trying to parse the WebResponse I get from a multiform POST. I want to pull out the H3 tags, but when I go to document.Load the stream, I get null errors like this: "Cannot implicitly convert type 'void' to 'HtmlAgilityPack.HtmlNodeCollection' "

Now I understand my webresponse starts out null, but it fills up eventually. How can I get this to run with the streamreader returning null automatically?

//web response stuff here
WebResponse ricochet = webrreq.GetResponse();
Stream stream2 = ricochet.GetResponseStream();
StreamReader reader2 = new StreamReader(stream2);
HtmlAgilityPack.HtmlDocument document= new HtmlAgilityPack.HtmlDocument();

//line with null error below
var collection = document.Load(reader2.ReadToEnd());
1
1
9/14/2011 4:07:59 PM

Accepted Answer

For Posterity:

I can't assign the collection to document.Load, I first have to Load the stream and then use the Agility pack to find the right nodes again

       var thingie = document.Load(reader2.ReadToEnd());
       var collection = thingie.DocumentNode.SelectNode("//etc");
2
9/13/2011 11:55:17 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow