Solved

WebBrowser control getting links

Posted on 2004-09-25
6
1,720 Views
Last Modified: 2008-01-09
I am trying to get all the links from an html page.  I am running into
difficulties on pages that have "frames".  I realize there might be issues
with framed sites but the site I'm interested in doesn't actually have
frames but does have asp header and side menus and I think that is the
problem.  It chokes on this line of code and gives me error 438: Object does
not support this property or method.

WebBrowser1.Document.links.length - 1

That's just plain weird because if you Add Watch to the WebBrowser control
and drill down the tree, it shows it to you!  What is going on here?
0
Comment
Question by:wym
6 Comments
 
LVL 10

Expert Comment

by:anv
ID: 12150029
0
 

Author Comment

by:wym
ID: 12151400
Thanks for answering but that's where I got my sample from in the first place.  It just doesn't like WebBrowser1.Document.links.length-1 on a site encased in headers and side menu.  I've seen so many other various samples and I'm shocked that no one ever came across a site they couldn't strip and found an alternative?

This is ALL my code.

Private Sub Command1_Click()

Open "links.txt" For Append As #1

For x = 0 To WebBrowser1.Document.links.length - 1
    If Left(WebBrowser1.Document.links(x), 26) = "http://www.osfi-bsif.gc.ca" Then
        Print #1, WebBrowser1.Document.links.Item(x)
    End If
Next x
Close #1
MsgBox "done"
End Sub

Private Sub Command2_Click()
WebBrowser1.Navigate2 Text1.Text
End Sub
0
 
LVL 11

Expert Comment

by:bingie
ID: 12151841
Whats the original URL?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:wym
ID: 12152246
This URL won't work

http://www.osfi-bsif.gc.ca/eng/publications/guidance/index_prudential.asp

But this URL will:

http://www.osfi-bsif.gc.ca/eng/publications/guidance/prudential.asp

I haven't figured out how to strip the frames off the home page but it's this:

http://www.osfi-bsif.gc.ca/eng/default.asp
0
 
LVL 14

Accepted Solution

by:
aelatik earned 50 total points
ID: 12153706
I think the method for enumeration is the problem, this one is working on all 3 URL's !

Private Sub Command1_Click()
        'WebBrowser1.Navigate "http://www.osfi-bsif.gc.ca/eng/default.asp"
        'WebBrowser1.Navigate "http://www.osfi-bsif.gc.ca/eng/publications/guidance/prudential.asp"
        WebBrowser1.Navigate "http://www.osfi-bsif.gc.ca/eng/publications/guidance/index_prudential.asp"
        While WebBrowser1.Busy: DoEvents: Wend
        Open "c:\links.txt" For Append As #1
        For i = 0 To WebBrowser1.Document.All.length - 1
            If UCase(WebBrowser1.Document.All(i).Tagname) = "A" Then
                If LCase(Left(WebBrowser1.Document.All(i).Href, 26)) = LCase("http://www.osfi-bsif.gc.ca") Then
                    Print #1, WebBrowser1.Document.All(i).Href
                End If
            End If
        Next
        Close #1
        MsgBox " done"
End Sub
0
 

Author Comment

by:wym
ID: 12156769
Excellent!  Thanks a lot!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now