我一直试图弄清楚如何做这件事一段时间了。我想找到“live_”的表单类名,我可以使用下面的代码做得很好,但我不确定如何在该表单标记中获取文本值没有遍历整个代码并在页面上获取所有其他表单文本值。
我在winform上使用了一个webbrowser控件。
我需要获取表单标记的代码是:
Dim theElementCollection As HtmlElementCollection = Nothing
theElementCollection = wbNewsFeed.Document.GetElementsByTagName("form")
For Each curElement As HtmlElement In theElementCollection
If curElement.GetAttribute("className").ToLower.Contains("live_") Then
Dim theID As String = curElement.GetAttribute("data-live")
End If
Next
上面的代码当前循环,直到它在该页面中找不到更多的表单标记。如果它找到了表单标记,那么它会查看该表单标记在其名称的任何部分是否包含 live _ 的类名。此代码工作正常,并找到该类的所有表单标记。但是,某些表单标记仍然具有该类但没有文本框,我也只想在该表单标记中搜索 。
html看起来与此相似:
<form class="live_574bf67566_58vvifkfkyu5237 commentable expand_mode" id="0_f"
onsubmit="return window.Event &&" action="change.php" method="post"
data-ft='{"ge":"]"}' rel="async" data-live='{"seq":"574bf67566_1857067654230"}'>
<input name="charset_test" type="hidden" value="6,52g,6b88">
<input name="fb_dtsg" type="hidden" value="AQB4SLmU" autocomplete="off">
[LOT of code here....]
<input class="hiddenInput" type="hidden" autocomplete="off" data-id="785fgj67-774">
<div class="innerWrap" data-reactid=".1l.1:4.0.$right.0.0.0.0.1.0.1">
<textarea name="add_comment_text" title="Write a comment..." class="textInput mentions" placeholder="Write a comment..." value="Write a comment..." data-id="57-986-gn-52">Write a comment...</textarea>
</div>
[some more code here]
</form>
所以我的问题是:如何查看仅当前表单标记区域并查找是否具有该文本框(。GetAttribute(“title”)。ToString.ToLower =“写评论......”)?
我尝试过以下操作:
Dim theElementCollection2 As HtmlElementCollection = Nothing
For Each curElement As HtmlElement In theElementCollection
If curElement.GetAttribute("className").ToLower.Contains("live_") Then
Dim theID As String = curElement.GetAttribute("data-live")
theElementCollection2 = curElement.Document.GetElementsByTagName("textarea")
For Each curElement2 As HtmlElement In theElementCollection2
Debug.Print(curElement2.GetAttribute("title").ToLower.ToString)
If curElement2.GetAttribute("title").ToLower.ToString = "write a comment..." Then
Debug.Print("Found! " & curElement2.GetAttribute("name"))
End If
Next
End If
Next
但这似乎只是遍及整个html页面......
感谢您的时间和帮助!
答案 0 :(得分:0)
似乎你需要:
curElement.Children.GetElementsByName("add_comment_text")(0)