rony2006 Posted October 21, 2017 Share Posted October 21, 2017 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:: expandcollapse popupsleep (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 More sharing options...
Danp2 Posted October 21, 2017 Share Posted October 21, 2017 First step is to identify the line where the error is occurring. You probably just need to add some IsObj() checks before assuming the object is good. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
rony2006 Posted October 21, 2017 Author Share Posted October 21, 2017 Now I run the script compiled and the line of error is around 20000 but m script has just about 1000 lines. I will run the script in au3 mode and I will see were is the error. Link to comment Share on other sites More sharing options...
Developers Jos Posted October 21, 2017 Developers Share Posted October 21, 2017 (edited) 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 October 21, 2017 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 More sharing options...
Moderators SmOke_N Posted October 22, 2017 Moderators Share Posted October 22, 2017 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now