Parsing WebResponse with Html Agility Pack

.net c# html-agility-pack

Question

The WebResponse I get from a multiform POST is being parsed by me. When I try to document, I can't get the H3 tags out. I get null errors after loading the stream, such as "Cannot implicitly convert type 'void' to 'HtmlAgilityPack.HtmlNodeCollection' "

I now realize that my web response initially contains nothing but slowly fills up. How can I make this work such that the streamreader always returns null?

//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 Future Use:

The collection won't let me attach it to a document. I must first load the stream before using the Agility pack to once again locate the proper nodes.

       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