LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.excel
external usenet poster
 
Posts: 93
Default Read (and parse) file on the web

Auric__ wrote:
Robert Baer wrote:

Excel macros are SO... undocumented.


Sure they are. Plenty of documentation for individual keywords. You're not
looking for that, you're looking for a broader concept than individual
keywords.

Need a WORKING example for reading the HTML source a URL (say
http://www.oil4lessllc.org/gTX.htm)


Downloading a web page (or any URI, really) is easy:

Declare Function URLDownloadToFile Lib "urlmon" _
Alias "URLDownloadToFileA" (ByVal pCaller As Long, _
ByVal szURL As String, ByVal szFileName As String, _
ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long

Sub foo()
Dim tmp, result, contents
tmp = Environ("TEMP")& Format$(Now, "yyyymmdd-hhmmss-")& "gTX.htm"
'download
result = URLDownloadToFile(0, "http://www.oil4lessllc.org/gTX.htm", _
tmp, 0, 0)
If result< 0 Then
'failed to download; error handler here
Else
'read from file
Open tmp For Binary As 1
contents = Space$(LOF(1))
Get #1, 1, contents
Close 1
'parse file here
'[...]
'cleanup
End If
Kill tmp
End Sub

(Note that URLDownloadToFile must be declared PtrSafe on 64-bit versions of
Excel.)

Dealing with the data downloaded is very dependant on what the page contains
and what you want to extract from it. That page you mentioned contains 2
images and 2 Javascript arrays; assuming you want the data from the arrays,
you could search for "awls[" or "aprd[" and get your data that way.

Rather than downloading to a file, it is possible to download straight to
memory, but I find it's simpler to use a temp file. Among other things,
downloading to memory requires opening and closing the connection yourself;
URLDownloadToFile handles that for you.

Thanks.
I know that the parsing is very dependent on the contents and what
one wants.
That is why i gave an example having at least one data array; similar
to what i may be parsing.
I too, like temp files because i can open them in random and/or
binary mode if need.
A bit of fun to read such backwards (like BMP files).

Thanks again.



 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
EOF Parse Text file Bam Excel Programming 2 September 24th 08 04:13 AM
Parse a txt file and save as csv? Frank Pytel Excel Programming 4 September 14th 08 09:23 PM
parse from txt file geebee Excel Programming 3 August 19th 08 07:55 PM
Parse File Location Mike Excel Worksheet Functions 5 October 3rd 07 04:05 PM
REQ: Simplest way to parse (read) HTML formatted data in via Excel VBA (or VB6) Steve[_29_] Excel Programming 3 August 25th 03 10:43 PM


All times are GMT +1. The time now is 04:11 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright 2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"