Jump to content

IE functions problem


 Share

Recommended Posts

Hello,

I developed and application that opens a website and copy first link from the page.

The site is http://mis.ercot.com/misapp/GetReports.do?reportTypeId=12331&reportTitle=DAM Settlement Point Prices&showHTMLView=&mimicKey  and each day there will be a new report publish at the top of the page.

I made a script that opens the site each 4 min and check if there is a new report (new link) or not.

 

This is my code::

 

sleep (1000)
$sURL = "http://mis.ercot.com/misapp/GetReports.do?reportTypeId=12331&reportTitle=DAM%20Settlement%20Point%20Prices&showHTMLView=&mimicKey"
$oIE = _IECreate ($sURL, 1,0)
sleep (1000)
_IELoadWait($oIE)
log1("Open site")
sleep (1000)

Local $oLinks = _IELinkGetCollection($oIE)
Local $iNumLinks = @extended

Local $sTxt = $iNumLinks & " links found" & @CRLF & @CRLF
For $oLink In $oLinks
    $sTxt &= $oLink.href & @CRLF

     If StringInStr($oLink.href, 'http') Then
ExitLoop 
endif
    Next

    Global $sitelink = $oLink.href
    log1("Ultimul link pe site:" & $sitelink )
    
_IEQuit($oIE)   


log1("Citeste ce se afla in lista lastuMDA" )
Global $aFileList = FileReadToArray(@ScriptDir & "\lastuMDA.txt")
    If @error = 1 Then
        MsgBox($MB_SYSTEMMODAL, "", "Path was invalid.")
        log1("Path was invalid." )
        Exit
    EndIf
    If @error = 4 Then
        MsgBox($MB_SYSTEMMODAL, "", "No file(s) were found.")
        log1("No file(s) were found.")
        Exit
    EndIf
    
    
        
    If $sitelink = $aFileList[0] Then
    log1("Linkuri la fel")
        ;msgbox(0, "", "Linkuri la fel")
        Else
        log1("Linkuri diferite")
        

        DownloadRaportErcotMDA()
        UploadErcotMDA()
        
Global $sSubject = "New Ercot MDA Report (" & $Data & ")"
Global $sBody = $sitelink
Global $sAttachFiles = @Scriptdir & "\raportMDA.csv"
Global $sFromName = "Ercot MDA Notificator"
    _Sendmail() 
        

        
        
        _FileWriteToLine(@ScriptDir & "\lastuMDA.txt", 1,$sitelink,True)
        
        FileDelete(@Scriptdir & "\raport.csv")
        FileDelete(@Scriptdir & "\raport.zip")

 

The problem is that from time to time I get the error: "variable must be of type object"

 

The problem is in this part:

sleep (1000)
$sURL = "http://mis.ercot.com/misapp/GetReports.do?reportTypeId=12331&reportTitle=DAM%20Settlement%20Point%20Prices&showHTMLView=&mimicKey"
$oIE = _IECreate ($sURL, 1,0)
sleep (1000)
_IELoadWait($oIE)
log1("Open site")
sleep (1000)

Local $oLinks = _IELinkGetCollection($oIE)
Local $iNumLinks = @extended

Local $sTxt = $iNumLinks & " links found" & @CRLF & @CRLF
For $oLink In $oLinks
    $sTxt &= $oLink.href & @CRLF

     If StringInStr($oLink.href, 'http') Then
ExitLoop 
endif
    Next

    Global $sitelink = $oLink.href

 

$sitelink is always first link from that page.

 

How I can solve this problem or how I can get first link of a webpage in a more efficient and error free way?

Link to comment
Share on other sites

  • Developers
14 minutes ago, rony2006 said:

but m script has just about 1000 lines

You need to add the #Include<> files to that at the place of the statement!

Run au3stripper with the /MO parameter and you get an idea which line it wrong when looking at the script_stripped.au3 file.

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Moderators
Global $sitelink = $oLink.href

That certainly doesn't look right!  $oLink is only used to step through the For/Next, it doesn't exist outside of it.

I also totally agree with Dan, you have no error checking, and you're almost guaranteed for some part of your "object" script to fail somewhere at some time.  You'll spend forever trying to figure out if you don't simplify your code into manageable functions that return error codes and return when there is an error... If @error or If Not IsObj is going to be your best friend!

If you insist on the above code, I'd probably change it to something like:

Local $oLinks = _IELinkGetCollection($oIE)
If Not IsObj($oLinks) Then Exit 11011 ;; some kind of error checking example
Local $iNumLinks = @extended

Local $sTxt = $iNumLinks & " links found" & @CRLF & @CRLF
Global $sitelink = ""

For $oLink In $oLinks
    $sTxt &= $oLink.href & @CRLF
    
    ; even checking href here isn't a safe way to do it, you'll get errors here too eventually
    If StringInStr($oLink.href, 'http') Then
        $sitelink = $oLink.href
        ExitLoop
    EndIf
    
Next

Although the use of locals and globals are confusing, I'm assuming you copied the locals from somewhere else... GL

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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...