Solved

WebBrowser control getting links

Posted on 2004-09-25
6
1,735 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

732 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