Jump to content

How to check if page load sucess AND the page is aviable?


Gillboss
 Share

Recommended Posts

How to check if page load sucess AND the page is aviable?

i try to do it:

#include <IE.au3>
$oIE = _IECreate ("")
Sleep(1000)
_IENavigate ($oIE, "http://www.google.com", 0)
$asd = _IELoadWait($oIE)
MsgBox(0,"",$asd)
_IENavigate ($oIE, "http://www.fdsasdgadfhadfh.com", 0)
$asd = _IELoadWait($oIE)
MsgBox(0,"",$asd)

its return same value, even www.fdsasdgadfhadfh.com is not existing

any?

Link to comment
Share on other sites

Straight from help

_IENavigate

--------------------------------------------------------------------------------

Directs an existing browser window to navigate to the specified URL.

#include <IE.au3>

_IENavigate ( ByRef $o_object, $s_url [, $f_wait = 1] )

Parameters

$o_object Object variable of an InternetExplorer.Application, Window or Frame object

$s_url URL to navigate to (e.g. "http://www.autoitscript.com")

$f_wait Optional: specifies whether to wait for page to load before returning

0 = Return immediately, not waiting for page to load

1 = (Default) Wait for page load to complete before returning

8)

NEWHeader1.png

Link to comment
Share on other sites

Well i made example where script tests if the page is available.

#include <IE.au3>
$url="http://www.notexistingwebpage.com"
$ie=_IECreate($url)
_IELoadWait($ie)
$source=_IEDocReadHTML($ie)
if StringInStr($source, "cannot display the web") > 0 then
    MsgBox(0,"Not real page","")
    Exit
Else
    MsgBox(0,"Succes","")
endif
Link to comment
Share on other sites

Additionally, _IENavigate() already has the _IELoadWait() built-in

Func _IENavigate(ByRef $o_object, $s_Url, $f_wait = 1)
    If Not IsObj($o_object) Then
        __IEErrorNotify("Error", "_IENavigate", "$_IEStatus_InvalidDataType")
        SetError($_IEStatus_InvalidDataType, 1)
        Return 0
    EndIf
    ;
    If Not __IEIsObjType($o_object, "documentContainer") Then
        __IEErrorNotify("Error", "_IENavigate", "$_IEStatus_InvalidObjectType")
        SetError($_IEStatus_InvalidObjectType, 1)
        Return 0
    EndIf
    ;
    $o_object.navigate($s_Url)
    If $f_wait Then
        _IELoadWait($o_object) ;**** <<<< HERE
        SetError(@error)
        Return -1
    EndIf
    SetError($_IEStatus_Success)
    Return -1
EndFunc   ;==>_IENavigate

8)

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

Well i made example where script tests if the page is available.

#include <IE.au3>
$url="http://www.notexistingwebpage.com"
$ie=_IECreate($url)
_IELoadWait($ie)
$source=_IEDocReadHTML($ie)
if StringInStr($source, "cannot display the web") > 0 then
    MsgBox(0,"Not real page","")
    Exit
Else
    MsgBox(0,"Succes","")
endif

its not help me, cuz my IE language is not English
Link to comment
Share on other sites

What he wants to do, is to check if the load succeeded in loading, not if it has loaded.

I've pointed him towards the ie.au3 UDF file, to look at the code for the _IELoadWait function, but he doesn't seem to understand what to do with it. Guess I'll have to show him an example...

Seems that approach is not possible, I was thinking it showed a different state for a 404 error or similar, but that doesn't seem to be the case. :/

Edited by FreeFry
Link to comment
Share on other sites

#include <ie.au3>

Dim $oIE = _IECreate("www.34jk5h4j3k5hj3453.com")
;~ Dim $oIE = _IECreate("www.google.com")

ConsoleWrite("Paged loaded successfully: " & Not _IEPageHasLocalResources($oIE) & @LF)

Func _IEPageHasLocalResources(ByRef $ovIE)
    Local $ovElements = _IETagNameGetCollection($ovIE, "img")
    Local $svElementSrc
    For $ovElement In $ovElements
;~      $svElementSrc = $ovElement.src
        If StringLeft($ovElement.src, 6) = "res://" Then Return 1
    Next
    Return 0
EndFunc

Not the most reliable(I believe), but it seems to work.

Edit:

Searched the forums and found a post by /dev/null which can properly see page-loading errors.

Modified code:

#include <ie.au3>

Dim $oIE = _IECreate("about:blank")

ObjEvent($oIE,"IEEvent_","DWebBrowserEvents2")
_IENavigate($oIE, "www.34jk5h4j3k5hj3453.com")
_IENavigate($oIE, "www.google.com")

Func IEEvent_NavigateError($pdisp, $url, $tf, $status,$cancel)
        $msg = "Problems loading page: " & $url & @CRLF
        $msg = $msg & "Status: " & $status & @CRLF
        MsgBox(0,"PROBLEMS",$msg)
EndFunc
Edited by FreeFry
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...