Solved

getting data from webpage that has frames

Posted on 2002-04-08
12
307 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
Technology Partners: 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!

 
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
 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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 In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
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…

762 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