【问题标题】:check html if a specific message appears如果出现特定消息,请检查 html
【发布时间】:2015-04-30 17:31:30
【问题描述】:

我有这个 Html sn-p

<div class="noticeBox">
     <div class="error">
          <img alt="Error" height="28" src="docs/pics/icon_error.png" title="Error" width="28"/><div>The password must: <ul><li>not be an old 

password</li></ul></div></div>
</div>

我怎样才能从上面的 Div 标签中得到消息“密码必须:不是旧密码”文本

我的应用程序更改了密码,但如果用户两次输入相同的密码,它会进入无限循环,我希望能够检测是否出现此消息。

我在我的 WPF 项目中使用 WinForm 浏览器并使用 C# 4.0

【问题讨论】:

  • 你能确认你是真的在使用 html-agility-pack 还是只是 webbrowser 控件(以及 html-agility-pack 标签只是无意中添加到问题中)?
  • 同时使用。浏览器控件和 HtmlAgilityPack。浏览器控件显示页面,敏捷包解析它并单击按钮。我可以在没有浏览器控件的情况下使用 HtmlAgilityPack 吗?

标签: c# wpf winforms html-agility-pack


【解决方案1】:

类似的东西:

HtmlDocument doc = new HtmlDocument();
 doc.LoadHtml(webBrowser1.DocumentText);
HtmlNode n = doc.DocumentElement.SelectSingleNode("//*[@class='noticeBox'"]//*[@class='error']);

if (n != null && n.InnerText.Equals("The password must: not be an old password"))
{
 // do stuff
}

【讨论】:

  • InnerText.Equals 将忽略相关句子中的
    • 标签?
  • 我在尝试 Expression 时遇到错误,必须评估为节点集。
【解决方案2】:
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(webBrowser.DocumentText);
HtmlNode n = doc.DocumentNode.SelectSingleNode("//*[contains(@class, 'noticeBox')]");

此代码有效。以上代码有语法错误

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-20
    • 2021-04-15
    • 2013-03-16
    • 2010-12-27
    • 2017-07-18
    • 1970-01-01
    • 2021-07-26
    • 1970-01-01
    相关资源
    最近更新 更多