我正在尝试解析我从多形式POST获得的WebResponse。我想拉出H3标签,但是当我去document.Load流时,我得到这样的空错误:“不能隐式地将类型'void'转换为'HtmlAgilityPack.HtmlNodeCollection'”
现在我明白我的webresponse开始为null,但它最终会填满。如何使用streamreader自动返回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());
答案 0 :(得分:2)
对于后人:
我无法将集合分配给document.Load,我首先要加载流然后使用Agility包再次找到正确的节点
var thingie = document.Load(reader2.ReadToEnd());
var collection = thingie.DocumentNode.SelectNode("//etc");