Webrowser get links [solved]

Posts 1–11 of 11 · Page 1 of 1
Webrowser get links [solved]
Code:
 Dim htmlDocument As HtmlDocument = Me.WebBrowser1.Document
        Dim htmlElementCollection As HtmlElementCollection = htmlDocument.Links
        Dim link2 As HtmlElementCollection
        link2 = WebBrowser1.Document.GetElementsByTagName("href")
        For Each img As HtmlElement In link2
            ListBox1.Items.Add(img.GetAttribute("href"))
        Next
The code dont work . . .
I want the code Gets all the Links of the Webpage and add to listbox

thanks
Explain more please.
I want the code gets all the links in the Web and add to listbox..
Quote Originally Posted by alvaritos View Post
I want the code gets all the links in the Web and add to listbox..
Again, use my toolkit. ParseAllLinks speaks for itself.
Code:
Dim Links As HtmlElementCollection = WebBrowser1.Document.GetElementByTagName("a")

For Each Link As HtmlElement in Links
Listbox1.Items.Add(Link.GetAttribute("href").ToString)
Next
But this will get the links only of the tag "a" ..

You cant just edit it to get the links of everytags, there are alots of ways..

Sorry my english.
Well Jason Im at My father PC, I cant download it now . . . And im borring so im making a new tool :S

Also thanks Lyoto
Quote Originally Posted by alvaritos View Post
Well Jason Im at My father PC, I cant download it now . . . And im borring so im making a new tool :S

Also thanks Lyoto
No problem, Anytime
But. . . You said just get elements of "a" I change It to "www" no?

Code:
Dim htmlElementCollection As HtmlElementCollection = htmlDocument.All
Dim link2 As HtmlElementCollection
link2 = WebBrowser1.Document.Links
For Each img As HtmlElement In link2
            varto = ListBox1.Items.Count
            ListBox1.Items.Add(img.GetAttribute("href"))
            Label2.Text = varto & " " & "Links"
            Label2.ForeColor = Color.Green
Just make a loop trough all elements of the page, And make like a check, If the attribute "href" is not null , then add it to the listbox..
Well solved but anyway thanks!
Okay marked solved.

[highlight=vb.net]
ListBox1.Items.AddRange(WebBrowser1.Document.GetEl ementsByTagName("a").Cast(Of HtmlElement)().Select(Function(h As HtmlElement) h.GetAttribute("href").ToString()).ToArray())
[/highlight]
Posts 1–11 of 11 · Page 1 of 1

Post a Reply

Tags for this Thread

None

Talk with us