sirkerry Posted October 5, 2009 Share Posted October 5, 2009 What's the best way to go about this? I want to find the rows in the table below that contain the string "CONTRACT" and then Click on the link/image that's on their row. <table width="100%"> <tr class="lightbg"> <th width="10%" >Image available</th> <th width="10%" >Date</th> <th width="20%" >Image type</th> <th width="70%" >Image description</th> </tr> <tr class="altcol1"> <td align="center" ><a href="TTS0009R.pgm?task=IMAGE&waDOCID=B09196AC.4LY&wnRnd=447519373"><img alt="" title="Document image is viewable on-line. [Disk]" border="0" src="/images/icondocdoc.png" width="32" height="32"></a></td> <td >11/09/2004</td> <td >LETTER</td> <td >NUV ACH/EPAY HELLO</td> </tr> <tr class="altcol2"> <td align="center" ><a href="TTS0009R.pgm?task=IMAGE&waDOCID=B09196AC.27R&wnRnd=447519373"><img alt="" title="Document image is viewable on-line. [Disk]" border="0" src="/images/icondocpdf.png" width="32" height="32"></a></td> <td >11/11/2004</td> <td >IMAGE</td> <td >CONTRACT</td> </tr> <tr class="altcol1"> <td align="center" ><a href="TTS0009R.pgm?task=IMAGE&waDOCID=B09196AC.27V&wnRnd=447519373"><img alt="" title="Document image is viewable on-line. [Disk]" border="0" src="/images/icondocpdf.png" width="32" height="32"></a></td> <td >11/11/2004</td> <td >IMAGE</td> <td >REFERENCES</td> </tr> etc... </table> Link to comment Share on other sites More sharing options...
exodius Posted October 5, 2009 Share Posted October 5, 2009 (edited) Maybe something like this? #include <Array.au3> #include <IE.au3> $oIE = _IECreate (@DesktopDir & "\a.html") ; This obviously will be replaced with your reference to $oIE $var = _IEDocReadHTML ($oIE) $RegExp = StringRegExp ($var, '(?:<TD align=.*href=")(.*)(?:"><IMG.*\s*<TD>.*</TD>\s*<TD>.*</TD>\s*<TD>CONTRACT</TD>)', 3) If Not @error Then _ArrayDisplay ($RegExp) ; Just so you can see if you get anything back from the regular expression. $oLinks = _IELinkGetCollection ($oIE) $iNumLinks = @extended For $oLink In $oLinks If StringInStr (StringReplace ($oLink.href, "&", "&"), $RegExp[0]) Then ; In my testing, for some reason the &'s would have amp; added after them, you may or may not need this StringReplace _IEAction ($oLink, "click") _IELoadWait($oIE) ExitLoop EndIf Next EndIf You're probably going to need to tweak it, but based on what I had to work with (making my own .html file with no way to see that it would actually work) this was what worked for me. Edited October 5, 2009 by exodius Link to comment Share on other sites More sharing options...
sirkerry Posted October 5, 2009 Author Share Posted October 5, 2009 Maybe something like this? #include <Array.au3> #include <IE.au3> $oIE = _IECreate (@DesktopDir & "\a.html") ; This obviously will be replaced with your reference to $oIE $var = _IEDocReadHTML ($oIE) $RegExp = StringRegExp ($var, '(?:<TD align=.*href=")(.*)(?:"><IMG.*\s*<TD>.*</TD>\s*<TD>.*</TD>\s*<TD>CONTRACT</TD>)', 3) If Not @error Then _ArrayDisplay ($RegExp) ; Just so you can see if you get anything back from the regular expression. $oLinks = _IELinkGetCollection ($oIE) $iNumLinks = @extended For $oLink In $oLinks If StringInStr (StringReplace ($oLink.href, "&", "&"), $RegExp[0]) Then ; In my testing, for some reason the &'s would have amp; added after them, you may or may not need this StringReplace _IEAction ($oLink, "click") _IELoadWait($oIE) ExitLoop EndIf Next EndIf You're probably going to need to tweak it, but based on what I had to work with (making my own .html file with no way to see that it would actually work) this was what worked for me. That works great, thanks! Link to comment Share on other sites More sharing options...
sirkerry Posted October 6, 2009 Author Share Posted October 6, 2009 (edited) This is my current script. I works fine for the first pass through, but I keep getting this error when it trys to loop though the links it finds: \\houtwo\mydocs\kharrison\My Documents\Scripts\gmacpdp.au3 (62) : ==> The requested action with this object has failed.: If StringInStr ($oLink.href, $RegExp[0]) Then If StringInStr ($oLink.href^ ERROR ->16:02:08 AutoIT3.exe ended.rc:1 +>16:02:10 AutoIt3Wrapper Finished So, I suspect I'm handling the array wrong, but I'm not really sure what I'm doing wrong here? expandcollapse popup#include <Array.au3> #include <File.au3> #include <IE.au3> #include <String.au3> RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\", "Download Directory", "REG_SZ", "C:\Working\GMAC\") Dim $CUBSdir = "C:\Working\" Dim $WorkDir = "C:\Working\GMAC\" Dim $i = 17 ;17 for PDP docs If FileExists($CUBSdir & "GMAC.CSV") Then $sFilePath = $CUBSdir & "GMAC.CSV" $LineCount = _FileCountLines($sFilePath) Dim $GMACacct = FileReadLine($sFilePath, $i) Dim $GMACshrt = StringRight($GMACacct, 9) Dim $GMACdash = StringLeft($GMACacct, 3) & "-" & StringMid($GMACacct, 4, 4) & "-" & StringRight($GMACacct, 5) Run("iexplore.exe") $oIE = _IECreate("https://xxxxxx.com/pdppublic/nxlogin.pgm") WinActivate("XXXX Technologies On-line Services - Windows Internet Explorer") $oForm = _IEFormGetObjByName($oIE, "loginfm") $oText = _IEFormElementGetObjByName($oForm, "user") _IEFormElementSetValue($oText, "xxxx") $oText = _IEFormElementGetObjByName($oForm, "password") _IEFormElementSetValue($oText, "xxxx") _IEFormSubmit($oForm) WinWaitActive("XXXX Technologies On-line Services - Windows Internet Explorer") $oFrame = _IEFrameGetObjByName ($oIE, "title") $pLinks = _IELinkGetCollection ($oFrame) $iNumLinks = @extended For $pLink In $pLinks $PDPexit = ($pLink.href) Next _IENavigate ($oIE, "https://xxxxxx.com/tts/tts0000r.pgm") WinWaitActive("XXXX Search Screen - Windows Internet Explorer") $oForm = _IEFormGetObjByName($oIE, "frmSelect") $oText = _IEFormElementGetObjByName($oForm, "waSCAcct") _IEFormElementSetValue($oText, $GMACacct) _IEFormSubmit ($oForm) WinWaitActive("Title Administration Account Documents - Windows Internet Explorer") _IEImgClick ($oIE, "buttonimages.png", "src") WinWaitActive("Title Administration Letters - Windows Internet Explorer") $sText = String(_IEBodyReadText ($oIE)) $NoRecs = StringInStr($sText, "No records found for this account.") If $NoRecs = 0 Then $FindDocs = _IEDocReadHTML ($oIE) $FindDocs2 = StringReplace ($FindDocs, "&", "&") $RegExp = StringRegExp ($FindDocs2, '(?:<TD align=.*href=")(.*)(?:"><IMG.*\s*<TD>.*</TD>\s*<TD>.*</TD>\s*<TD>CONTRACT</TD>)', 3) If Not @error Then ;_ArrayDisplay ($RegExp) $oLinks = _IELinkGetCollection ($oIE) $iNumLinks = @extended For $oLink In $oLinks If StringInStr ($oLink.href, $RegExp[0]) Then _IEAction ($oLink, "click") _IELoadWait($oIE) $sText = String(_IEBodyReadText ($oIE)) $ImgWill = StringInStr($sText, "This image will open") If $ImgWill = 0 Then $oInputs = _IETagNameGetCollection ($oIE, "embed") For $oInput In $oInputs MsgBox(0, "Got Here1", "Got Here1") $Between1 = String($oInput.outerHTML) $Between2 = StringRight($Between1, 65) $oFileDL = StringLeft($Between2, 54) ExitLoop Next Else $oInputs = _IETagNameGetCollection ($oIE, "a") For $oInput In $oInputs MsgBox(0, "Got Here2", "Got Here2") $Between1 = String($oInput.outerHTML) $Between2 = StringRight($Between1, 86) $oFileDL = StringLeft($Between2, 54) ExitLoop Next EndIf $oFileDLurl = "https://xxxxxx.com" & $oFileDL $oFileDLlast4 = StringRight($oFileDL, 4) $oFileDLname = "C:\Working\GMAC\" & $GMACacct & " GMC CONTRACT" & $oFileDLlast4 InetGet($oFileDLurl, $oFileDLname) WinActivate("Title Administration - Image - Windows Internet Explorer") _IEImgClick ($oIE, "buttonimages.png", "src") EndIf Next EndIf EndIf Exit _IENavigate ($oIE, $PDPexit) WinWaitActive("XXXX Technologies On-line Services - Windows Internet Explorer") EndIf Edited October 7, 2009 by sirkerry Link to comment Share on other sites More sharing options...
sirkerry Posted October 8, 2009 Author Share Posted October 8, 2009 bump Link to comment Share on other sites More sharing options...
exodius Posted October 8, 2009 Share Posted October 8, 2009 (edited) The problem isn't with the array, it's with the $oLink object when you try to reference its .href property... Not 100% if it'll help, but maybe try adding a check for _IELinkGetCollection to not work? expandcollapse popup#include <Array.au3> #include <File.au3> #include <IE.au3> #include <String.au3> RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\", "Download Directory", "REG_SZ", "C:\Working\GMAC\") Dim $CUBSdir = "C:\Working\" Dim $WorkDir = "C:\Working\GMAC\" Dim $i = 17 ;17 for PDP docs If FileExists($CUBSdir & "GMAC.CSV") Then $sFilePath = $CUBSdir & "GMAC.CSV" $LineCount = _FileCountLines($sFilePath) Dim $GMACacct = FileReadLine($sFilePath, $i) Dim $GMACshrt = StringRight($GMACacct, 9) Dim $GMACdash = StringLeft($GMACacct, 3) & "-" & StringMid($GMACacct, 4, 4) & "-" & StringRight($GMACacct, 5) ;~ Run("iexplore.exe") $oIE = _IECreate("https://xxxxxx.com/pdppublic/nxlogin.pgm") ;~ WinActivate("XXXX Technologies On-line Services - Windows Internet Explorer") $oForm = _IEFormGetObjByName($oIE, "loginfm") $oText = _IEFormElementGetObjByName($oForm, "user") _IEFormElementSetValue($oText, "xxxx") $oText = _IEFormElementGetObjByName($oForm, "password") _IEFormElementSetValue($oText, "xxxx") _IEFormSubmit($oForm) ;~ WinWaitActive("XXXX Technologies On-line Services - Windows Internet Explorer") $oFrame = _IEFrameGetObjByName ($oIE, "title") $pLinks = _IELinkGetCollection ($oFrame) For $pLink In $pLinks $PDPexit = ($pLink.href) Next _IENavigate ($oIE, "https://xxxxxx.com/tts/tts0000r.pgm") ;~ WinWaitActive("XXXX Search Screen - Windows Internet Explorer") $oForm = _IEFormGetObjByName($oIE, "frmSelect") $oText = _IEFormElementGetObjByName($oForm, "waSCAcct") _IEFormElementSetValue($oText, $GMACacct) _IEFormSubmit ($oForm) ;~ WinWaitActive("Title Administration Account Documents - Windows Internet Explorer") _IEImgClick ($oIE, "buttonimages.png", "src") ;~ WinWaitActive("Title Administration Letters - Windows Internet Explorer") $sText = String(_IEBodyReadText ($oIE)) $NoRecs = StringInStr($sText, "No records found for this account.") If $NoRecs = 0 Then $FindDocs = _IEDocReadHTML ($oIE) $FindDocs2 = StringReplace ($FindDocs, "&", "&") $RegExp = StringRegExp ($FindDocs2, '(?:<TD align=.*href=")(.*)(?:"><IMG.*\s*<TD>.*</TD>\s*<TD>.*</TD>\s*<TD>CONTRACT</TD>)', 3) If Not @error Then ;_ArrayDisplay ($RegExp) $oLinks = _IELinkGetCollection ($oIE) If Not @error Then For $oLink In $oLinks If StringInStr ($oLink.href, $RegExp[0]) Then _IEAction ($oLink, "click") _IELoadWait($oIE) $sText = String(_IEBodyReadText ($oIE)) $ImgWill = StringInStr($sText, "This image will open") If $ImgWill = 0 Then $oInputs = _IETagNameGetCollection ($oIE, "embed") For $oInput In $oInputs MsgBox(0, "Got Here1", "Got Here1") $Between1 = String($oInput.outerHTML) $Between2 = StringRight($Between1, 65) $oFileDL = StringLeft($Between2, 54) ExitLoop Next Else $oInputs = _IETagNameGetCollection ($oIE, "a") For $oInput In $oInputs MsgBox(0, "Got Here2", "Got Here2") $Between1 = String($oInput.outerHTML) $Between2 = StringRight($Between1, 86) $oFileDL = StringLeft($Between2, 54) ExitLoop Next EndIf $oFileDLurl = "https://xxxxxx.com" & $oFileDL $oFileDLlast4 = StringRight($oFileDL, 4) $oFileDLname = "C:\Working\GMAC\" & $GMACacct & " GMC CONTRACT" & $oFileDLlast4 InetGet($oFileDLurl, $oFileDLname) ;~ WinActivate("Title Administration - Image - Windows Internet Explorer") _IEImgClick ($oIE, "buttonimages.png", "src") EndIf Next Else MsgBox (0, "Error!", "_IELinkGetCollection failed!") EndIf EndIf EndIf Exit _IENavigate ($oIE, $PDPexit) ;~ WinWaitActive("XXXX Technologies On-line Services - Windows Internet Explorer") EndIf *Edit - I commented out all of the lines that you don't need, you don't need the Win* functions because the _IE* functions have a parameter that, by default, is set to wait until the page is done loading before going on to the next step in your script. Edited October 8, 2009 by exodius 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