Solved

foxpro - using Shell.Explorer

Posted on 2013-11-01
3
1,438 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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…
In  today’s increasingly digital world, managed service providers (MSPs) fight for their customers’ attention, looking for ways to make them stay and purchase more services. One way to encourage that behavior is to develop a dependable brand of prod…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

759 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

18 Experts available now in Live!

Get 1:1 Help Now