C# 使用Html Agility Pack解析WebResponse
我试图解析我从一篇各种形式的帖子中得到的网络回复。我想取出H3标记,但是当我转到document.Load流时,我会得到如下空错误:“无法隐式地将类型'void'转换为'HtmlAgilityPack.HtmlNodeCollection'” 现在我知道我的webresponse开始时是空的,但它最终会填满。在streamreader自动返回null的情况下,如何使其运行C# 使用Html Agility Pack解析WebResponse,c#,.net,html-agility-pack,C#,.net,Html Agility Pack,我试图解析我从一篇各种形式的帖子中得到的网络回复。我想取出H3标记,但是当我转到document.Load流时,我会得到如下空错误:“无法隐式地将类型'void'转换为'HtmlAgilityPack.HtmlNodeCollection'” 现在我知道我的webresponse开始时是空的,但它最终会填满。在streamreader自动返回null的情况下,如何使其运行 //web response stuff here WebResponse ricochet = webrreq.GetRe
//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());
为子孙后代:
我无法将集合分配给document.Load,我首先必须加载流,然后使用Agility pack再次找到正确的节点
var thingie = document.Load(reader2.ReadToEnd());
var collection = thingie.DocumentNode.SelectNode("//etc");
我不明白你想实现什么-你收到的多部分帖子不是HTML文档…我收到一个网页,上面有数据作为回应。使用reader2.ReadToEnd()填写textBox.Text时,它工作正常,我可以看到html代码。但是我不能直接将其放入HtmlDocument.Load函数中,因为它是nullSidenote:使用接受流的
Load()
重载。无需先作为字符串读取。您需要首先解析POST响应以提取textBox.Text的内容,然后将该内容馈送到document.Load