在命令窗口中输入以下命令:
oIE = createobject( 'internetexplorer.application')
oIE.navigate2('http://www.web898.net/pages.php?xuh=16')
? oIE.Document.body.innerhtml
便可以看到在屏幕上输出了网页的内容,如果你了解了网页控件的属性和方法,就可以随 心所欲获得一个网页的任何内容了。
也可以采用另外一种读取内容的方式:
*readurl.prg
LPARAMETERS UrlName
if empty(UrlName)
wait window '参数错误!' nowait
return ''
endif
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)
* what application is using Internet services?
sAgent = 'VPF 6.0'
hInternetSession = InternetOpen(sAgent, INTERNET_OPEN_TYPE_PRECONFIG, ;
'', '', SYNCHRONOUS)
* debugging line - uncomment to see session handle
* WAIT WINDOW 'Internet session handle: ' + LTRIM(STR(hInternetSession))
IF hInternetSession = 0
WAIT WINDOW 'Internet session cannot be established' TIME 2
RETURN ''
ENDIF
hUrlFile = InternetOpenUrl(hInternetSession, UrlName, '', ;
0, INTERNET_FLAG_RELOAD, 0)
* debugging line - uncomment to see URL handle
* WAIT WINDOW 'URL Handle: ' + LTRIM(STR(hUrlFile))
IF hUrlFile = 0
WAIT WINDOW 'URL cannot be opened' nowait
RETURN ''
ENDIF
Local lcReturn
lcReturn = ''
DO WHILE .T.
* set aside a big buffer
sReadBuffer = SPACE(32767)
lBytesRead = 0
m.OK = InternetReadFile(hUrlFile, @sReadBuffer, ;
LEN(sReadBuffer), @lBytesRead)
* debugging code - uncomment if necessary
*WAIT WINDOW 'hURLFile: ' + LTRIM(STR(hURLFile)) + CR + ;
* 'lBytesRead: ' + LTRIM(STR(lBytesRead)) + CR ;
* + 'm.OK : ' + LTRIM(STR(m.OK))
lcReturn = lcReturn + sReadBuffer
* uncomment to watch the changes to the memo file
* MODIFY MEMO hurl.memo
* error trap - either a read failure or read past eof()
IF m.OK = 0 OR lBytesRead = 0
EXIT
ENDIF
ENDDO
* close all the handles we opened
=InternetCloseHandle(hUrlFile)
=InternetCloseHandle(hInternetSession)
* return the number of bytes read
return lcReturn
这样,在命令窗口中输入:readurl('http://www.web898.net/')一样可以看到相应的结果。