VB.NET Grab URL From Webbrowser1 [closed]
Want to improve this question? Add details and clarify the problem by editing this post.
开发者_Python百科Closed 7 years ago.
Improve this questionHow can i grab this url and paste it in a textbox?
Logout (Kassy Daniels) · Help
from this in webbrowser1
i want it to grab the /logout.php? url cause each user is different
and just paste it in a textbox1 when you hit a button
Assuming your webbrowser is WebBrowser1
,
Using WebBrowser1.Document.Links
will get you a HTMLElementCollection
of all of the links on the page.
You can iterate through those, and check the OuterHtml
element of each of those links (which will give you a string that contains the raw link, the IDs, etc.) for the text your are looking for (in this case logout?
).
Using the substring command, extract that URL, and eliminate the surrounding text, and you can plug that right into the textbox.
Update: Using Firebug or your favorite DOM tool, you can find that the logout link is in the root div of the document
Dim rootDiv As HtmlElement = WebBrowser1.Document.GetElementById("root")
Dim links As HtmlElementCollection = rootDiv.GetElementsByTagName("a")
Dim index As Integer
For i As Integer = 0 To links.Count - 1
If links(i).InnerHtml.Contains("Logout") Then
index = i
Exit For
End If
Next i
Dim stringofLink As String = links(index).OuterHtml
If the page changes in structure, this should be somewhat resilient to it, but you may need to generalize it further. Process stringofLink however you want to break it up (find the ampersand that you need and then copy from the question mark to that point).
精彩评论