Ho cercato di capire come fare per fare questo per un po 'di tempo. Sto cercando di trovare il nome di classe form di "live_" che posso fare bene con il codice qui sotto, ma non sono sicuro su come ottenere un valore di testo all'interno di tale tag senza scorrere l'intero codice e ottenere ogni altro testo valore sulla pagina.
Sto usando un controllo del webbrowser sul mio winform.
Il codice che ho per ottenere il tag form è questo:
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
Il codice sopra scorre attualmente fino a quando non trova più tag di forma all'interno di quella pagina. Se trova un tag form, guarda se quel tag form contiene un nome classe di live_ in qualsiasi parte del suo nome. Questo codice funziona bene e trova tutti i tag form di quella classe. Tuttavia, alcuni tag del modulo hanno ancora quella classe ma nessuna casella di testo che sto cercando anche all'interno di quel tag .
L'html è simile a questo:
<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>
Quindi la mia domanda è: come faccio a cercare solo attraverso l'area del tag del modulo corrente e trovando se ha quella casella di testo (.GetAttribute ("title"). ToString.ToLower = "scrivi un commento ...") ?
Ho provato a fare quanto segue:
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
Ma questo sembra solo scorrere l'intera pagina html ancora ...
Grazie per il tuo tempo e aiuto!
Sembra che tu abbia bisogno di:
curElement.Children.GetElementsByName("add_comment_text")(0)