Solved

getting data from webpage that has frames

Posted on 2002-04-08
12
304 Views
Last Modified: 2010-05-02
How can I, programmatically, get info from a table within the frame of a webpage?

Preece
0
Comment
Question by:Preece
  • 7
  • 5
12 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6926370
what kind of info do you need?
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6926399
From where do you see that page?
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6926418
with webbrowser component:
Add a reference to microsoft html object library
add a webbrowser component
Paste this code:


Dim ieDoc As HTMLDocument
Private Sub Form_Load()
wb1.Navigate "www.angelfire.com/realm/vb-shared/index.html"
End Sub


Private Sub wb1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
If (pDisp Is wb1.object) Then
    Dim i As Integer
    Dim tbl As Object
    Dim cell As IHTMLElement
    Set ieDoc = wb1.Document
    For i = 1 To ieDoc.frames.length
        For Each tbl In ieDoc.body.All
            If tbl.tagName = "TABLE" Then
                For Each cell In tbl.cells
                    Debug.Print cell.innerText
                Next
            End If
        Next tbl
   
    Next i
End If
End Sub
0
 
LVL 16

Accepted Solution

by:
Richie_Simonetti earned 100 total points
ID: 6926424
To use with Internet explorer itself you need to add a reference to microsoft internet control instead of webbrowser control.

Dim ieDoc As HTMLDocument
dim withevents IE as InternetExplorer

Private Sub Form_Load()
set IE = new InternetExplorer
with ie
     .Navigate "www.angelfire.com/realm/vb-shared/index.html"
     .visible =true
end with
End Sub


Private Sub IE_DocumentComplete(ByVal pDisp As Object, URL As Variant)
If (pDisp Is IE) Then
    Dim i As Integer
    Dim tbl As Object
    Dim cell As IHTMLElement
    Set IEdoc = IE.Document
    For i = 1 To ieDoc.frames.length
        For Each tbl In ieDoc.body.All
            If tbl.tagName = "TABLE" Then
                For Each cell In tbl.cells
                    Debug.Print cell.innerText
                Next
            End If
        Next tbl
   
    Next i
End If
End Sub
0
 
LVL 12

Author Comment

by:Preece
ID: 6926616
Hey, Richie:

I tried something like this and it worked:


    If webX.Document.frames.length > 0 Then
        Dim hDoc As HTMLDocument, i As Integer
        Set hDoc = webX.Document
        For i = 0 To hDoc.frames.length - 1
            For Each Tbl In hDoc.frames(i).Document.All
                  'do something
            next Tbl
        next i
    endif


Preece
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6928064
Two questions:
If your page hasn't frames, it doesn't read any table.
Where do you use that code? I suposse in Document_complete, right?
Your code is a little compact than mine. I did mine in a rush.
Be carefull, that code would enumerate .all tags, if you don't check whitch tag is....
Cheers
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.

 
LVL 12

Author Comment

by:Preece
ID: 6929506
Hey Richie,

First of all, I want to thank you for all of the help that you have given in the past.  I say, you must be paid to answer EE Q's all day!  I'd like that job!  

1)  "If your page hasn't frames, it doesn't read any table..."
I am gathering info from a number of sites, one of which uses a frameset.  So I use this code on that particular page.  

2)  I first use a WebBrowser control and navigate to a web site.  I then pass the  WebBrowser control (webX) to the code that you see above.  Then I loop thru the frames and tables, inspecting each table for the presence of a value in a particular cell.  Once that value is found, then I extract the values from the target table!  I don't even bother with tags, as some pages that I use don't have tags on the tables!

Preece
0
 
LVL 12

Author Comment

by:Preece
ID: 6929514
also, I have Tbl defined as an HTMLTable
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6929569
Yeah, thank you! I remember you.
Regarding HTMLTable (and other html elements). Sometimes, all collections doesn't manage very well for each ... loops for some reason that i hadn't time to know why.
I had to face a time ago with that problem, all col returns all tags and sometimes the loop asign a value to tbl (as in this example) which is not a table at all and the code is messed up!
0
 
LVL 12

Author Comment

by:Preece
ID: 6929645
It's amazing how creative you can get with the use of error handlers!

Preece
0
 
LVL 12

Author Comment

by:Preece
ID: 7241752
Thanks Richie!  Sorry it took so long to get back to this question.  Also, I have another if you wouldn't mind taking a look!  

http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20337204.html

Thanks again!
Preece
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7243171
Thanks for "A" grade.
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

Suggested Solutions

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

947 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

22 Experts available now in Live!

Get 1:1 Help Now