[英]Extract the value of a HTML node using VB.NET
I am trying to extract a value of a HTML node using VB.NET. 我正在尝试使用VB.NET提取HTML节点的值。
This is the form: 形式如下:
<html>
<head>
<title>Submit Form</title>
<meta name="referrer" content="origin"/>
<meta http-equiv="x-ua-compatible" content="IE=edge" />
</head>
<body onload="javascript:document.forms[0].submit()">
<noscript>
<p>
<strong>Note:</strong> Since your browser does not support JavaScript, you must press the Resume button once to proceed.
</p>
</noscript>
<form method="post" action="https://test.aspx">
<input type="hidden" name="SAMLResponse" value="123456789"/>
<noscript><input type="submit" value="Resume"/></noscript>
</form>
</body>
</html>
I would like to extract 我想提取
123456789
I already tryed this: 我已经尝试过了:
Dim SAMLResponse As String = CType(xmlURLDecodedXML.Descendants().Where(Function(x) x.Name.LocalName = "SAMLResponse").FirstOrDefault(), String)
In your case, try with this (with assumption: the node input of SAMLResponse will not change, because the attribute position will change too) : 在您的情况下,请尝试以下操作(假设:SAMLResponse的节点输入不会更改,因为属性位置也会更改):
Dim myArray() As XElement = MyXelement.Descendants().ToArray
Dim myname As String = ""
Dim myValue As String = ""
For a = 1 To myArray.Count
If myArray(a - 1).Name.ToString = "input" Then
Try
If myArray(a - 1).Attributes.ToArray(1).Value = "SAMLResponse" Then
myValue = myArray(a - 1).Attributes.ToArray(2).Value
End If
Catch ex As Exception
End Try
End If
Next
in your html: 在您的html中:
<input type="hidden" name="SAMLResponse" value="123456789"/>
so
The Node Name is input
The First Attribute is Hidden
The Second Attribute is SAMLResponse
The Third Attribute is 123456789
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.