目前我正在处理一个来自网站的c#格式的HtmlDocument:
return doc.DocumentNode.SelectSingleNode("//span[@title=input]").InnerText;我想从一个标题为"input“的span中获取内部文本。上面是我当前的代码,但我在尝试运行它时收到了一个NullReferenceException。为了从"input“中检索文本,我的隐式参数应该是什么?
发布于 2012-10-26 02:49:23
return doc.DocumentNode.SelectSingleNode("//span[@title='"+input+"']").InnerText;因为输入不是字符串,所以必须连接起来以适应参数。感谢大家的帮助!
发布于 2012-10-25 03:14:16
在XPath表达式中,必须用引号分隔字符串:
return doc.DocumentNode.SelectSingleNode("//span[@title='input']").InnerText;普通input将尝试使用该名称匹配节点并替换其值。
发布于 2012-10-25 03:28:10
确保具有title属性的span元素存在,并在HtmlAgilityPack的HtmlDocument对象中将值作为“input”。
要进行适当的检查,请尝试这段代码:
if (doc.DocumentNode != null)
{
var span = doc.DocumentNode.SelectSingleNode("//span[@title='input']");
if (span != null)
return span.InnerText;
}https://stackoverflow.com/questions/13056097
复制相似问题