Solved

getting data from webpage that has frames

Posted on 2002-04-08
12
305 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

772 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