Solved

getting data from webpage that has frames

Posted on 2002-04-08
12
302 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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 …
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…
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…

760 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

23 Experts available now in Live!

Get 1:1 Help Now