Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Control eh?
Message
From
08/11/2010 14:23:18
 
 
To
08/11/2010 14:17:18
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Miscellaneous
Thread ID:
01488307
Message ID:
01488533
Views:
77
If you don't need to actually see the webpage, you can use this code to get the complete HTML
*Function GetDataFrom URL
LPARAMETERS pcUrlName
DECLARE INTEGER InternetOpen IN wininet.DLL STRING sAgent, ;
      INTEGER lAccessType, STRING sProxyName, ;
      STRING sProxyBypass, INTEGER lFlags

DECLARE INTEGER InternetOpenUrl IN wininet.DLL ;
   INTEGER hInternetSession, STRING sUrl, STRING sHeaders,;
   INTEGER lHeadersLength, INTEGER lFlags, INTEGER lContext

DECLARE INTEGER InternetReadFile IN wininet.DLL INTEGER hfile, ;
      STRING @sBuffer, INTEGER lNumberofBytesToRead, INTEGER @lBytesRead

DECLARE short InternetCloseHandle IN wininet.DLL INTEGER hInst

#DEFINE INTERNET_OPEN_TYPE_PRECONFIG 0
#DEFINE INTERNET_OPEN_TYPE_DIRECT 1
#DEFINE INTERNET_OPEN_TYPE_PROXY 3
#DEFINE SYNCHRONOUS 0
#DEFINE INTERNET_FLAG_RELOAD 2147483648
#DEFINE CR CHR(13)

local lsAgent, lhInternetSession, lhUrlFile, llOk, lnOk, lcRetVal, lcReadBuffer, lnBytesRead

* what application is using Internet services?
lsAgent = "VPF 5.0"

lhInternetSession = InternetOpen( lsAgent, INTERNET_OPEN_TYPE_PRECONFIG, ;
      '', '', SYNCHRONOUS)

* debugging line - uncomment to see session handle
* WAIT WINDOW "Internet session handle: " + LTRIM(STR(hInternetSession))

IF lhInternetSession = 0
   WAIT WINDOW "Internet session cannot be established" TIME 2
   RETURN .null.
ENDIF

lhUrlFile = InternetOpenUrl( lhInternetSession, pcUrlName, '', 0, ;
                             INTERNET_FLAG_RELOAD, 0)

* debugging line - uncomment to see URL handle
* WAIT WINDOW "URL Handle: " + LTRIM(STR(hUrlFile))

IF lhUrlFile = 0
   WAIT WINDOW "URL cannot be opened" Timeout 5
   RETURN .null.
ENDIF

lcRetVal = ""
llOk = .t.

DO WHILE llOK
   * set aside a big buffer
   lsReadBuffer = SPACE(32767)
   lnBytesRead = 0
   lnOK = InternetReadFile( lhUrlFile, @lsReadBuffer, LEN(lsReadBuffer), @lnBytesRead)

   if ( lnBytesRead > 0 )
      lcRetVal = lcRetVal + left( lsReadBuffer, lnBytesRead )
   endif

   * error trap - either a read failure or read past eof()
   llOk = ( lnOK = 1 ) and ( lnBytesRead > 0 )
ENDDO

* close all the handles we opened
InternetCloseHandle( lhUrlFile )
InternetCloseHandle( lhInternetSession )

* return the URL contents
RETURN lcRetVal
>* I've tried quite a few ways to get this done, with no luck so for
>* I need to paste the selected web page into a General field and it's not happening
>* The most recent attempt is below and resides in _WEBBROWSER41.NAVIGATECOMPLETE2
>
>LPARAMETERS pdisp, url
>USE masterdata
>#define OLECMDID_SELECTALL 17
>THIS.ExecWB(OLECMDID_SELECTALL, 0)
>APPEND BLANK
>replace captured WITH DATETIME()
>BROWSE FIELDS WEBPAGE
>#define OLECMDID_PASTE 17
>THIS.ExecWB(OLECMDID_PASTE, 0)
>
>
>
>
>
>
>
>
>
>
>>>>The KEYBOARD command puts keystrokes into VFP buffer. An ActiveX control wouldn't see them. What are you trying to accomplish?
>>>>
>>>>
>>>>>The first two lines of code below work fine. I am not sure why the displayed website is not being selected by the CTRL A. Have I blundered?
>>>>>
>>>>>THIS._Webbrowser41.NAVIGATE2('http://www.google.com')
>>>>>
>>>>>THISFORM.REFRESH
>>>>>
>>>>>KEYBOARD"{CTRL+A}"
>>>
>>>I am trying to capture the text from a web page and eventually write it to a memo field
>>
>>Hey Grady. I created a web page called w1.htm in folder c:\demos, with the source (note the spaces after < and before > are intentional, so I can embed the HTML source in a UT post).
>>
>>< html >
>>< body >
>>< input id="test" type="text" >
>>< /body >
>>< /html >
>>
>>Below is sample code you can try by executing line by line in the Command Window, which opens that web page above, sets the value of the text field (in case you want to know how to read/write to the value of fields), and then sets cHTML to the entire HTML of the web page.
>>
>>o=NEWOBJECT("_webform",HOME()+"gallery\_webview")
>>o.Show
>>o.oleWebBrowser.Navigate2("c:\demos\w1.htm")
>>o.oleWebBrowser.document.getElementByID("test").innerText="Testing 123"
>>cHTML=o.oleWebBrowser.document.body.outerHTML
>>
>>Tip. If you want to run VFP code to occur after a web page is loaded after calling Navigate2(), then put your event code in the NavigateComplete() event method of oleWebBrowser, which fires after the web page is full loaded into the IE web browser control.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform