Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

foxpro - using Shell.Explorer

Posted on 2013-11-01
3
Medium Priority
?
1,656 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 43

Accepted Solution

by:
pcelba earned 2000 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 43

Expert Comment

by:pcelba
ID: 39616440
You are welcome!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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…
Media Temple is thrilled to announce the launch of our new Partner Program, specifically designed to empower digital agencies and adtech platforms by offering white-glove support and exclusive hosting enhancements to optimize their sites and their c…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

885 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