如何使用wpf从Web浏览器控件中的任何标记获取值
我在字符串类型变量中有一个完整的网页源代码。
这些代码如下: –
Twitter / Authorize an application html { display:none; } html { display: block; } You've granted access to ThisTweetControl!
Next, return this PIN to complete the authorization process: 6107346
var twttr = twttr || {}; twttr.form_authenticity_token = '015cfb03a75wdsfgdf6753dsfb0770c4dab7f3f89b'; if (self == top) { document.documentElement.style.display = 'block'; }
在上面的代码行中有一个带有一些值的代码标记
,我需要在变量中获取数值。 6107346
提前致谢。
如果你使用System.Windows.Controls.WebBrowser
控件然后这应该工作,但它假设你只有一个CODE
标记:
var myTagValue = (wbBrowser.Document as mshtml.HTMLDocument) .getElementsByTagName("CODE") .OfType() .First() .innerText
您需要引用Internet Explorer的COM库: Microsoft HTML Object Library
。 getElementsByTagName
返回所有匹配标记的列表,无论它们在HTML中的位置