Solved

foxpro - using Shell.Explorer

Posted on 2013-11-01
3
1,444 Views
Last Modified: 2013-11-01
I'm currently using the Shell.Explorer object to automate data extraction from the web.
The code that I found and changed slightly is below. I have a free foxpro form that loads a table and scans through the urls in a field and then call the code below as a seperate .prg to access the url.

I realize that there must be a more efficient way to load the class once or define the class in the url and then call the method in class for each url, but since I haven't worked much with Foxpro classes, I don't know how to do it. How can I load the class once in the form and call the method to access the html for each url in the table that I'm scanning?

I'm only interested in using  "Shell.Explorer" object and no other programmable browser.


This is the code that is called in a file call AccessWeb.prg

LPARAMETERS url
owb = createobject("WebBrowserForm")
owb.getinnerhtml("Opening web page",url)


DEFINE CLASS WebBrowserForm AS FORM

      ADD OBJECT WebBrowser AS OLECONTROL WITH OLECLASS = "Shell.Explorer"

      PROCEDURE GetInnerText
      LPARAMETERS cMessage, cURL
      LOCAL cHTML
      IF EMPTY(cURL)
            RETURN ''
      ENDIF
      WITH This.WebBrowser
            .Navigate2(cURL)
            DO WHILE .ReadyState <> 4 AND .ReadyState <> 3
            ENDDO
      ENDWITH
      WAIT CLEAR
      DO while VARTYPE(This.WebBrowser.Document.body) <> [O]
        
      ENDDO

      cHTML = This.WebBrowser.Document.All[0].outerhtml
        SUSPEND 
      RETURN cHTML
      
      
      PROCEDURE GetInnerHTML
      LPARAMETERS cMessage, cURL
      LOCAL cHTML
      IF EMPTY(cURL)
            RETURN ''
      ENDIF
      WITH This.WebBrowser
            .Navigate2(cURL)
            DO WHILE .ReadyState <> 4 AND .ReadyState <> 3
            ENDDO
      ENDWITH
      WAIT CLEAR
      
      DO while VARTYPE(This.WebBrowser.Document.body) <> [O]
        
      ENDDO
      
      cHTML = This.WebBrowser.Document.All[0].outerhtml
      SUSPEND 
      RETURN cHTML

    
ENDDEFINE

Open in new window



This is the code within the form that I use to create the class and return the html of the web page that is sent to the class:

chtml = AccessWeb(UrlListings.URL)

Open in new window

0
Comment
Question by:esak2000
  • 2
3 Comments
 
LVL 41

Accepted Solution

by:
pcelba earned 500 total points
ID: 39616328
Maybe the more efficient way exists but it does not bring any significant improvement to you...

I don't know what improvement you mean but the class instantiation is very fast in Visual FoxPro and the slowest process is the internet access here.

Of course, you could keep the form open with the ShellExplorer instantiated and call the Navigate2() method but then you have to wait for results again and again. And internet access requires to reinstantiate the class from time to time because some web page downloads can simply freeze... So the only thing I would recommend is to place some timeout check into your DO WHILE - ENDDO loops.

What is more important is missing wait command in your DO WHILE loops:
DO WHILE .ReadyState <> 4 AND .ReadyState <> 3
ENDDO

This loads CPU nearly to 100% by VFP app. Instead leave other apps to get some CPU time by waiting interval:

DO WHILE .ReadyState <> 4 AND .ReadyState <> 3
  WAIT WINDOW "Waiting for the web..." TIME 0.2
ENDDO

And the timeout:

LOCAL lnTime
lnTime = SECONDS()
DO WHILE .ReadyState <> 4 AND .ReadyState <> 3
  WAIT WINDOW "Waiting for the web..." TIME 0.2
  IF SECONDS() - m.lnTime > 120   && 2 minutes timeout
     *-- Web inactive
     EXIT
  ENDIF
ENDDO
0
 

Author Closing Comment

by:esak2000
ID: 39616393
Thank you for the quick response and the pointers!
0
 
LVL 41

Expert Comment

by:pcelba
ID: 39616440
You are welcome!
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

Microsoft Visual FoxPro (short VFP) is a programming language with it’s own IDE and database, ranking somewhat between Access and VB.NET + SQL Server (Express). Product Description: http://msdn.microsoft.com/en-us/vfoxpro/default.aspx (http://msd…
Lotus Notes – formerly IBM Notes – is an email client application, while IBM Domino (earlier Lotus Domino) is an email server. The client possesses a set of features that are even more advanced as compared to that of Outlook. Likewise, IBM Domino is…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

932 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

12 Experts available now in Live!

Get 1:1 Help Now