Re: how to confirm whether the webpage is accessible? [message #55145] |
Fri, 03 August 2007 13:07 |
Michael Galloy
Messages: 1114 Registered: April 2006
|
Senior Member |
|
|
On Aug 3, 1:45 am, lingl...@gmail.com wrote:
> Hi
> I have used the IDLnetURL to access some webpages.If the webpages
> address is wrong, the warning message box will appear.To avoid the
> warning message, It is necessary to confirm whether the webpage is
> accessible.if available, the IDLnetURL object can be used to vist the
> webpage, otherwise ,quit.So my question is about how to confirm
> whether the webpage is accessible.
I added some simple error checking to the previous get_url_content
routine (see below for full source code). It can be used like:
IDL> content = get_url_content('http://michaelgalloy.com',
error=error) ; good
IDL> help, error
ERROR LONG = 0
IDL> content = get_url_content('http://michaellgalloy.com',
error=error) ; server not found
IDL> help,
error
ERROR LONG = 1
IDL> content = get_url_content('http://michaelgalloy.com/invalid',
error=error) ; 404 error
IDL> help, error
ERROR LONG = 1
Mike
--
www.michaelgalloy.com
;+
; Get the content for the given URL.
;
; :Returns: string, strarr
;
; :Params:
; `url` : in, required, type=string
; complete URL to get content for, including "http://"
;
; :Keywords:
; `error` : out, optional, type=boolean
; pass a named variable, will be set if an error occurs in
getting the
; content of the URL (in which case the return value will be the
empty
; string)
;-
function get_url_content, url, error=error
compile_opt strictarr
error = 0L
errorNumber = 0L
catch, errorNumber
if (errorNumber ne 0L) then begin
catch, /cancel
error = 1L
if (obj_valid(ourl)) then obj_destroy, ourl
return, ''
endif
ourl = obj_new('IDLnetURL')
content = ourl->get(url=url, /string_array)
obj_destroy, ourl
return, content
end
|
|
|