Herb191 Posted May 6, 2011 Share Posted May 6, 2011 expandcollapse popup#include <IE.au3> #Include <Date.au3> $results = test("Lawnmowers") MsgBox(0, "", $results) Func test($kw_to_search_for) $shopping_results_on_the_page = "no" Do $oIE = _IECreate("http://www.google.com", 0, 1) check_for_errors(@error) Until @error = 0 Do $oForm = _IEFormGetObjByName($oIE, "f") check_for_errors(@error) Until @error = 0 Do $oQuery = _IEFormElementGetObjByName($oForm, "q") check_for_errors(@error) Until @error = 0 Do _IEFormElementSetValue($oQuery, $kw_to_search_for) ;enters the KW's that will be searched check_for_errors(@error) Until @error = 0 Do _IEFormSubmit($oForm, 0) check_for_errors(@error) Until @error = 0 Do _IELoadWait($oIE) check_for_errors(@error) Until @error = 0 ;Checks to see if there are Google shopping results on the page $sMyString = "Shopping results for" Do $oLinks = _IELinkGetCollection($oIE) check_for_errors(@error) Until @error = 0 For $oLink In $oLinks Do $sLinkText = _IEPropertyGet($oLink, "innerText") check_for_errors(@error) Until @error = 0 If StringInStr($sLinkText, $sMyString) Then $shopping_results_on_the_page = "yes" ExitLoop EndIf Next _IEQuit($oIE) Return $shopping_results_on_the_page EndFunc ;==>google_PR_for_kw Func check_for_errors($error) If $error <> 0 Then $file = FileOpen("error.log", 1) If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf FileWrite($file, _NowTime() & @CRLF) FileWrite($file, $error & @CRLF) FileWrite($file, @CRLF) FileClose($file) EndIf EndFunc ;==>check_for_errors What’s the best way to keep this function from exiting when it gets an error? I basically I want it to keep trying until it works. It works most of the time but when I loop though it with a for loop I occasionally get the following errors: --> IE.au3 V2.4-0 Error from function _IECreate (Browser Object Creation Failed) --> IE.au3 V2.4-0 Error from function _IEFormGetObjByName, $_IEStatus_InvalidDataType --> IE.au3 V2.4-0 Error from function _IEFormElementGetObjByName, $_IEStatus_InvalidDataType --> IE.au3 V2.4-0 Error from function _IEFormElementSetValue, $_IEStatus_InvalidDataType --> IE.au3 V2.4-0 Error from function _IEFormSubmit, $_IEStatus_InvalidDataType --> IE.au3 V2.4-0 Error from function _IELoadWait, $_IEStatus_InvalidDataType --> IE.au3 V2.4-0 Error from function _IELinkGetCollection, $_IEStatus_InvalidDataType C:\Documents and Settings\Owner\Desktop\test\test\test1.au3 (633) : ==> Variable must be of type "Object".: For $oLink In $oLinks For $oLink In $oLinks^ ERROR Link to comment Share on other sites More sharing options...
smartee Posted May 6, 2011 Share Posted May 6, 2011 hi herb191, Search the help file for ObjEvent(), it shows you how to create custom error handlers, interestingly/ironically/luckily, the example uses the IE object. Hope this helps, -smartee Link to comment Share on other sites More sharing options...
GMK Posted May 6, 2011 Share Posted May 6, 2011 You might also try something like: #include <IE.au3> #Include <Date.au3> $results = test("Lawnmowers") MsgBox(0, "", $results) Func test($kw_to_search_for) $shopping_results_on_the_page = "No" $oIE = _IECreate("http://www.google.com", 0, 1) $oForm = _IEFormGetObjByName($oIE, "f") $oQuery = _IEFormElementGetObjByName($oForm, "q") _IEFormElementSetValue($oQuery, $kw_to_search_for) ;enters the KW's that will be searched _IEFormSubmit($oForm, 1) ;Checks to see if there are Google shopping results on the page $sMyString = "Shopping results for" $oLinks = _IELinkGetCollection($oIE) If IsObj($oLinks) Then For $oLink In $oLinks $sLinkText = _IEPropertyGet($oLink, "innerText") If StringInStr($sLinkText, $sMyString) Then $shopping_results_on_the_page = "Yes" ExitLoop EndIf Next Else MsgBox(0, "", "Links not found.") EndIf _IEQuit($oIE) Return $shopping_results_on_the_page EndFunc ;==>google_PR_for_kw 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