Klexen Posted July 13, 2007 Share Posted July 13, 2007 Okay I made a script that I want to search az auto glass in google, then if sponsored links are listed, I want it to click each one in which I have listed. Is there a way to take the name of links and add it to something so that I can check to see if that link is listed. If it is I want it to click one of the links, go back to google search page and click the next link on the page, until it has clicked all the links I have listed to click by text. I know there is a better way to do it than im doing it, I was wondering if someone can help me out with my code? expandcollapse popup#include <IE.Au3> While 1 ;BlockInput(1) If ProcessExists("IEXPLORE.EXE") Then ProcessClose("IEXPLORE.EXE") $sURL = "http://www.google.com/search?hl=en&q=az+auto+glass&btnG=Search" $oIE = _IECreate($sURL, 0, 0, 0) $HWND = _IEPropertyGet($oIE, "hwnd") WinSetState($HWND, "", @SW_MAXIMIZE) _IEAction($oIE, "visible") _IELoadWait($o _IELinkGetCollection($oIE) $pixel = 0xFFF9DD $xy = PixelSearch(0,0,@DesktopWidth,@DesktopHeight,$pixel);Searches entire desktop If @error Then _IEQuit($oIE) $pixel2 = 0x7DCF53 $x1y1 = PixelSearch(0,0,@DesktopWidth,@DesktopHeight,$pixel2);Searches entire desktop MouseMove($x1y1[0],$x1y1[1], 30) MouseClick("right",$x1y1[0],$x1y1[1]) Send("{UP 5}") Send("{ENTER}") Else _IELinkClickByText($oIE,"Auto Glass Quotes") _IELoadWait($oIE) _IEAction($oIE, "visible") Send ("{BACKSPACE}") _IELinkClickByText($oIE,"Auto Glass Repair Phoenix") _IELoadWait($oIE) _IEAction($oIE, "visible") Send ("{BACKSPACE}") _IELinkClickByText($oIE,"Phoenix AZ Auto Glass") _IELoadWait($oIE) _IEAction($oIE, "visible") Send ("{BACKSPACE}") _IELinkClickByText($oIE,"Auto Glass Replaced") _IELoadWait($oIE) _IEAction($oIE, "visible") Send ("{BACKSPACE}") _IELinkClickByText($oIE,"Safelite Auto Glass") _IELoadWait($oIE) _IEAction($oIE, "visible") Send ("{BACKSPACE}") _IELinkClickByText($oIE,"Bachman Auto Glass LLC") _IELoadWait($oIE) _IEAction($oIE, "visible") Send ("{BACKSPACE}") _IELinkClickByText($oIE,"AAI Official Website") _IELoadWait($oIE) _IEAction($oIE, "visible") Send ("{BACKSPACE}") _IELinkClickByText($oIE,"Windshield Replacement") _IELoadWait($oIE) _IEAction($oIE, "visible") Send ("{BACKSPACE}") _IELinkClickByText($oIE,"Auto Glass/Windshield Pro") _IELoadWait($oIE) _IEAction($oIE, "visible") Send ("{BACKSPACE}") _IELinkClickByText($oIE,"TG's Auto Glass Arizona") _IELoadWait($oIE) _IEAction($oIE, "visible") Send ("{BACKSPACE}") _IELinkClickByText($oIE,"Phoenix Auto Glass Quotes") _IELoadWait($oIE) _IEAction($oIE, "visible") Send ("{BACKSPACE}") _IELinkClickByText($oIE,"Sun Devil Auto Repair") _IELoadWait($oIE) _IEAction($oIE, "visible") Send ("{BACKSPACE}") _IELinkClickByText($oIE,"Arizona Auto Glass Quotes") _IELoadWait($oIE) _IEAction($oIE, "visible") Send ("{BACKSPACE}") Send ("^{F5}") EndIf WEnd Link to comment Share on other sites More sharing options...
mikehunt114 Posted July 13, 2007 Share Posted July 13, 2007 Yep, look like your code can be cleaned up quite a bit. First off, what are you using PixelSearch for? IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font] Link to comment Share on other sites More sharing options...
GMK Posted July 13, 2007 Share Posted July 13, 2007 I didn't know what the PixelSearch was for either, so I didn't include it, but here's my take on it: #include <IE.Au3> Dim $sText[13] $sText[0] = "Auto Glass Quotes" $sText[1] = "Auto Glass Repair Phoenix" $sText[2] = "Phoenix AZ Auto Glass" $sText[3] = "Auto Glass Replaced" $sText[4] = "Safelite Auto Glass" $sText[5] = "Bachman Auto Glass LLC" $sText[6] = "AAI Official Website" $sText[7] = "Windshield Replacement" $sText[8] = "Auto Glass/Windshield Pro" $sText[9] = "TG's Auto Glass Arizona" $sText[10] = "Phoenix Auto Glass Quotes" $sText[11] = "Sun Devil Auto Repair" $sText[12] = "Arizona Auto Glass Quotes" While 1 ;BlockInput(1) $sURL = "http://www.google.com/search?hl=en&q=az+auto+glass&btnG=Search" $oIE = _IECreate($sURL, 0, 0, 1) $HWND = _IEPropertyGet($oIE, "hwnd") WinSetState($HWND, "", @SW_MAXIMIZE) WinActivate($HWND) WinWaitActive($HWND) _IEAction($oIE, "visible") For $i = 0 To 12 _IELinkClickByText($oIE, $sText[$i]) If Not @error Then SplashTextOn("Klexen", $sText[$i] & " found") Sleep(2000) SplashOff() _IEAction($oIE, "back") _IELoadWait($oIE) EndIf Next _IEQuit($oIE) WEnd Link to comment Share on other sites More sharing options...
mikehunt114 Posted July 13, 2007 Share Posted July 13, 2007 (edited) A bit different from GMK's, but similar. The biggest difference is the use of __IELinkClickByText (notice the two underscores). Dale's function searches for an exact match, whereas this will match a sub-string. It is a pure copy of Dale's function with that one revision. Using the regular function will not work for you in this case I don't think. Also, it's probably a good idea to navigate right back to the search page, instead of hitting "back". This will prevent any inconsistencies if the page has a redirect or any other problematic events.expandcollapse popup#include <IE.Au3> ;Populate an array with your desired link text: Dim $aLinkText[13] $aLinkText[0] = "Auto Glass Quotes" $aLinkText[1] = "Auto Glass Repair Phoenix" $aLinkText[2] = "Phoenix AZ Auto Glass" $aLinkText[3] = "Auto Glass Replaced" $aLinkText[4] = "Safelite Auto Glass" $aLinkText[5] = "Bachman Auto Glass LLC" $aLinkText[6] = "AAI Official Website" $aLinkText[7] = "Windshield Replacement" $aLinkText[8] = "Auto Glass/Windshield Pro" $aLinkText[9] = "TG's Auto Glass Arizona" $aLinkText[10] = "Phoenix Auto Glass Quotes" $aLinkText[11] = "Sun Devil Auto Repair" $aLinkText[12] = "Arizona Auto Glass Quotes" $sURL = "http://www.google.com/search?hl=en&q=az+auto+glass&btnG=Search" $oIE = _IECreate($sURL, 1, 0) ;Why not let it try and attach? I see no reason not to wait for the page to load either... $HWND = _IEPropertyGet($oIE, "hwnd") WinSetState($HWND, "", @SW_MAXIMIZE) _IEAction($oIE, "visible") $count = 0 For $i = 0 To UBound($aLinkText) - 1 $colLinks = _IELinkGetCollection($oIE) $clickLink = __IELinkClickByText($oIE, $aLinkText[$i]) If $clickLink = -1 Then $count += 1 _IENavigate($oIE, $sURL) Next ConsoleWrite("Number of links clicked succesfully: " & $count & " of " & Ubound($aLinkText) & @CR & @CR) ;Dale's function with just a StringInStr change Func __IELinkClickByText(ByRef $o_object, $s_linkText, $i_index = 0, $f_wait = 1) If Not IsObj($o_object) Then __IEErrorNotify("Error", "__IELinkClickByText", "$_IEStatus_InvalidDataType") SetError($_IEStatus_InvalidDataType, 1) Return 0 EndIf ; Local $found = 0, $link, $linktext, $links = $o_object.document.links $i_index = Number($i_index) For $link In $links $linktext = $link.outerText & "" ; Append empty string to prevent problem with no outerText (image) links If StringInStr($linktext, $s_linkText) Then If ($found = $i_index) Then $link.click If $f_wait Then _IELoadWait($o_object) SetError(@error) Return -1 EndIf SetError($_IEStatus_Success) Return -1 EndIf $found = $found + 1 EndIf Next __IEErrorNotify("Warning", "__IELinkClickByText", "$_IEStatus_NoMatch") SetError($_IEStatus_NoMatch) ; Could be caused by parameter 2, 3 or both Return 0 EndFunc ;==>_IELinkClickByTextPS: I'm not seeing all the links you'd like to click on that search page.Edit: typos Edited July 13, 2007 by mikehunt114 IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font] Link to comment Share on other sites More sharing options...
Klexen Posted July 13, 2007 Author Share Posted July 13, 2007 (edited) Thanks guys! This is the code I'm using and it's working great. I was wondering if it was some how possible to only click the links that are under Sponsered Links, instead of links in the body. expandcollapse popup#include <IE.Au3> ;Populate an array with your desired link text: Dim $aLinkText[13] While 1 $aLinkText[0] = "Auto Glass Quotes" $aLinkText[1] = "Auto Glass Repair Phoenix" $aLinkText[2] = "Phoenix AZ Auto Glass" $aLinkText[3] = "Auto Glass Replaced" $aLinkText[4] = "Safelite Auto Glass" $aLinkText[5] = "Bachman Auto Glass LLC" $aLinkText[6] = "AAI Official Website" $aLinkText[7] = "Windshield Replacement" $aLinkText[8] = "Auto Glass/Windshield Pro" $aLinkText[9] = "TG's Auto Glass Arizona" $aLinkText[10] = "Phoenix Auto Glass Quotes" $aLinkText[11] = "Sun Devil Auto Repair" $aLinkText[12] = "Arizona Auto Glass Quotes" $sURL = "http://www.google.com/search?hl=en&q=auto+glass+phoenix&btnG=Search" $oIE = _IECreate($sURL, 1, 0) ;Why not let it try and attach? I see no reason not to wait for the page to load either... $HWND = _IEPropertyGet($oIE, "hwnd") WinSetState($HWND, "", @SW_MAXIMIZE) _IEAction($oIE, "visible") Sleep(1200) $pixel = 0xFFF9DD $xy = PixelSearch(0,0,@DesktopWidth,@DesktopHeight,$pixel) If @error Then _IEQuit($oIE) $pixel2 = 0x7DCF53 $x1y1 = PixelSearch(0,0,@DesktopWidth,@DesktopHeight,$pixel2) MouseMove($x1y1[0],$x1y1[1], 30) MouseClick("right",$x1y1[0],$x1y1[1]) Send("{UP 5}") Send("{ENTER}") Else $count = 0 For $i = 0 To UBound($aLinkText) - 1 $colLinks = _IELinkGetCollection($oIE) $clickLink = __IELinkClickByText($oIE, $aLinkText[$i]) If $clickLink = -1 Then $count += 1 _IENavigate($oIE, $sURL) Next ConsoleWrite("Number of links clicked succesfully: " & $count & " of " & Ubound($aLinkText) & @CR & @CR) _IEQuit($oIE) EndIf WEnd ;Dale's function with just a StringInStr change Func __IELinkClickByText(ByRef $o_object, $s_linkText, $i_index = 0, $f_wait = 1) If Not IsObj($o_object) Then __IEErrorNotify("Error", "__IELinkClickByText", "$_IEStatus_InvalidDataType") SetError($_IEStatus_InvalidDataType, 1) Return 0 EndIf ; Local $found = 0, $link, $linktext, $links = $o_object.document.links $i_index = Number($i_index) For $link In $links $linktext = $link.outerText & "" ; Append empty string to prevent problem with no outerText (image) links If StringInStr($linktext, $s_linkText) Then If ($found = $i_index) Then $link.click If $f_wait Then _IELoadWait($o_object) SetError(@error) Return -1 EndIf SetError($_IEStatus_Success) Return -1 EndIf $found = $found + 1 EndIf Next __IEErrorNotify("Warning", "__IELinkClickByText", "$_IEStatus_NoMatch") SetError($_IEStatus_NoMatch) ; Could be caused by parameter 2, 3 or both Return 0 EndFunc ;==>_IELinkClickByText Edited July 13, 2007 by Klexen Link to comment Share on other sites More sharing options...
GMK Posted July 13, 2007 Share Posted July 13, 2007 (edited) That's better than mine, mikehunt114, but I don't see that the line...$colLinks = _IELinkGetCollection($oIE)...really does anything. You don't need to get the link collection before clicking on any links. Klexen, I'm still looking for a way to click on just the sponsored links. Edit: And I still don't understand what the pixel search is for. :-\ Edited July 13, 2007 by GMK Link to comment Share on other sites More sharing options...
Klexen Posted July 13, 2007 Author Share Posted July 13, 2007 Okay the pixelsearch is for checking to see if sponsored links are showing at the top of the search page. If it's there then it runs the script, if it's not then it doesn't. It checks the color of the Sponsored links. It's like a pale orange. Do you see what I'm talking about now? Also usually if sponsored links doesn't show it's because of the proxy I'm going through is in another country, so for some reason it won't show. So when it sees sponsored links arent there it changes the proxy to another location. Hence, the second pixelsearch. Make sense yet ? Thanks again for your guys' help! Link to comment Share on other sites More sharing options...
PsaltyDS Posted July 13, 2007 Share Posted July 13, 2007 So which is the purpose of this, to rip off Google, or to rip off AZ Auto Glass...? Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
GMK Posted July 13, 2007 Share Posted July 13, 2007 Okay the pixelsearch is for checking to see if sponsored links are showing at the top of the search page. If it's there then it runs the script, if it's not then it doesn't. It checks the color of the Sponsored links. It's like a pale orange. Do you see what I'm talking about now? Also usually if sponsored links doesn't show it's because of the proxy I'm going through is in another country, so for some reason it won't show. So when it sees sponsored links arent there it changes the proxy to another location. Hence, the second pixelsearch.Make sense yet ?Thanks again for your guys' help!Makes sense now, but you may be able to do it better by looking for a DIV or table with a certain name or ID. Link to comment Share on other sites More sharing options...
DaleHohm Posted July 13, 2007 Share Posted July 13, 2007 See if this approach helps. The sponsored links are contained in a DIV with id=tads #include <IE.au3> $oIE = _IECreate ("http://www.google.com/search?hl=en&q=auto+glass+phoenix&btnG=Search", 1) $oSponsoredLinksDiv = _IEGetObjById($oIE, "tads") $oLinks = _IETagNameGetCollection($oSponsoredLinksDiv, "a") $iNumLinks = @extended MsgBox(0, "Link Info", $iNumLinks & " links found") For $oLink In $oLinks MsgBox(0, "Link Text", $oLink.outerText) Next Dale Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model Automate input type=file (Related) Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded Better Better? IE.au3 issues with Vista - Workarounds SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead? Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble Link to comment Share on other sites More sharing options...
Klexen Posted July 13, 2007 Author Share Posted July 13, 2007 (edited) See if this approach helps. The sponsored links are contained in a DIV with id=tads expandcollapse popup#include <IE.au3> $oIE = _IECreate ("http://www.google.com/search?hl=en&q=auto+glass+phoenix&btnG=Search", 1) $oSponsoredLinksDiv = _IEGetObjById($oIE, "tads") $oLinks = _IETagNameGetCollection($oSponsoredLinksDiv, "a") $iNumLinks = @extended MsgBox(0, "Link Info", $iNumLinks & " links found") For $oLink In $oLinks MsgBox(0, "Link Text", $oLink.outerText) NextoÝ÷ Ø6¥{ú®¢×jW²¢é"rIì°h½ì¨º²P1wÝ8Zµ§-¹©eË +çwÜÚ0jr"^éí¶{h¶¡×«ÞméhÀض''%É-ébK"Ø^J'±êÞt¸§Æ¶¢§víêâZºÚ"µÍÚ[ÛYH ÒQK]LÉÝÂØÚÒ[] JBÔÜ[]H[^HÚ][ÝÚY[È^[H ÌÍØS[Õ^ÌMBÚ[HBÌÍØS[Õ^ÌHH ][ÝÐ]]ÈÛÜÈ][ÝÉ][ÝÂÌÍØS[Õ^ÌWHH ][ÝÐ]]ÈÛÜÈZÙ[^ ][ÝÂÌÍØS[Õ^ÌHH ][ÝÔÙ[^V]]ÈÛÜÉ][ÝÂÌÍØS[Õ^Ì×HH ][ÝÐ]]ÈÛÜÈXÙY ][ÝÂÌÍØS[Õ^ÍHH ][ÝÔØY[]H]]ÈÛÜÉ][ÝÂÌÍØS[Õ^ÍWHH ][ÝÐXÚX[]]ÈÛÜÈÉ][ÝÂÌÍØS[Õ^ÍHH ][ÝÐPRHÙXÚX[ÙXÚ]I][ÝÂÌÍØS[Õ^Í×HH ][ÝÕÚ[ÚY[XÙ[Y[ ][ÝÂÌÍØS[Õ^ÎHH ][ÝÐ]]ÈÛÜËÕÚ[ÚY[É][ÝÂÌÍØS[Õ^ÎWHH ][ÝÕÉÌÎNÜÈ]]ÈÛÜÈ^ÛI][ÝÂÌÍØS[Õ^ÌLHH ][ÝÔÙ[^]]ÈÛÜÈ][ÝÉ][ÝÂÌÍØS[Õ^ÌLWHH ][ÝÔÝ[][]]ÈZ][ÝÂÌÍØS[Õ^ÌLHH ][ÝÐ^ÛH]]ÈÛÜÈ][ÝÉ][ÝÂÌÍØS[Õ^ÌL×HH ][ÝÖÛHÛÜÉ][ÝÂÌÍÜ^[H ÑÑLÂÌÍÞ^LHH^[ÙXÚ ÚÝÜÚYÚÝÜZYÚ ÌÍÜ^[B[ÝÙS[ÝJ ÌÍÞ^LVÌK ÌÍÞ^LVÌWKÌ B[ÝÙPÛXÚÊ ][ÝÜYÚ ][ÝË ÌÍÞ^LVÌK ÌÍÞ^LVÌWJBÙ[ ][ÝÞÕT _I][ÝÊBÙ[ ][ÝÞÑSTI][ÝÊHÌÍÜÕTH ][ÝÚËÝÝÝËÛÛÙÛKÛÛKÜÙXÚÚY[[ÜOX]]ÊÙÛÜÊÜÙ[^ [ØÏTÙXÚ ][ÝÂÌÍÛÒQHHÒQPÜX]J ÌÍÜÕTK HÕÚHÝ]]H[]XÚÈHÙYHÈXÛÛÝÈØZ]ÜHYÙHÈØYZ]ÌÍÒÓHÒQTÜQÙ] ÌÍÛÒQK ][ÝÚÛ ][ÝÊBÚ[Ù]Ý]J ÌÍÒÓ ][ÝÉ][ÝËÕ×ÓPVSRVJBÒQPXÝ[Û ÌÍÛÒQK ][ÝÝÚXI][ÝÊBÛY L BÌÍÜ^[HQÌÍÞHH^[ÙXÚ ÚÝÜÚYÚÝÜZYÚ ÌÍÜ^[ BYÜ[ÒQT]Z] ÌÍÛÒQJBÌÍÜ^[H ÑÑLÂÌÍÞ^LHH^[ÙXÚ ÚÝÜÚYÚÝÜZYÚ ÌÍÜ^[B[ÝÙS[ÝJ ÌÍÞ^LVÌK ÌÍÞ^LVÌWKÌ B[ÝÙPÛXÚÊ ][ÝÜYÚ ][ÝË ÌÍÞ^LVÌK ÌÍÞ^LVÌWJBÙ[ ][ÝÞÕT _I][ÝÊBÙ[ ][ÝÞÑSTI][ÝÊH[ÙBÌÍØÛÝ[HÜ ÌÍÚHHÈPÝ[ ÌÍØS[Õ^ HHB ÌÍØÛÛ[ÜÈHÒQS[ÑÙ]ÛÛXÝ[Û ÌÍÛÒQJB ÌÍØÛXÚÓ[ÈH×ÒQS[ÐÛXÚÐU^ ÌÍÛÒQK ÌÍØS[Õ^ÉÌÍÚWJBY ÌÍØÛXÚÓ[ÈHLH[ ÌÍØÛÝ[ ÏHBÒQS]YØ]J ÌÍÛÒQK ÌÍÜÕT B^ÛÛÛÛUÜ]J ][ÝÓ[XÙ[ÜÈÛXÚÙYÝXØÙÙ[N ][ÝÈ [È ÌÍØÛÝ[ [È ][ÝÈÙ ][ÝÈ [ÈXÝ[ ÌÍØS[Õ^ H [ÈÔ [ÈÔBÒQT]Z] ÌÍÛÒQJB[YÑ[Ñ[IÌÎNÜÈ[Ý[ÛÚ]ÝHÝ[Ò[ÝÚ[ÙB[È×ÒQS[ÐÛXÚÐU^ TY ÌÍÛ×ÛØXÝ ÌÍÜ×Û[Õ^ ÌÍÚWÚ[^H ÌÍÙÝØZ]HJBYÝÓØ ÌÍÛ×ÛØXÝ H[×ÒQQÜÝYJ ][ÝÑÜ][ÝË ][Ý××ÒQS[ÐÛXÚÐU^ ][ÝË ][ÝÉÌÍ×ÒQTÝ]×Ò[[Y]UI][ÝÊBÙ]Ü ÌÍ×ÒQTÝ]×Ò[[Y]UKJB][YÂØØ[ ÌÍÙÝ[H ÌÍÛ[Ë ÌÍÛ[Ý^ ÌÍÛ[ÜÈH ÌÍÛ×ÛØXÝØÝ[Y[[Ü ÌÍÚWÚ[^H[X ÌÍÚWÚ[^ BÜ ÌÍÛ[È[ ÌÍÛ[Ü ÌÍÛ[Ý^H ÌÍÛ[ËÝ]^ [È ][ÝÉ][ÝÈÈ[[HÝ[ÈÈ][Ø[HÚ]ÈÝ]^ [XYÙJH[ÜÂYÝ[Ò[Ý ÌÍÛ[Ý^ ÌÍÜ×Û[Õ^ H[Y ÌÍÙÝ[H ÌÍÚWÚ[^ H[ ÌÍÛ[ËÛXÚÂY ÌÍÙÝØZ][ÒQSØYØZ] ÌÍÛ×ÛØXÝ BÙ]ÜÜB]LB[YÙ]Ü ÌÍ×ÒQTÝ]×ÔÝXØÙÜÊB]LB[Y ÌÍÙÝ[H ÌÍÙÝ[ ÈB[Y^×ÒQQÜÝYJ ][ÝÕØ[É][ÝË ][Ý××ÒQS[ÐÛXÚÐU^ ][ÝË ][ÝÉÌÍ×ÒQTÝ]×ÓÓX]Ú ][ÝÊBÙ]Ü ÌÍ×ÒQTÝ]×ÓÓX]Ú HÈÛÝ[HØ]ÙYH[Y]ÈÜÝ][[ÈÏOIÝ×ÒQS[ÐÛXÚÐU^ Edited July 13, 2007 by Klexen Link to comment Share on other sites More sharing options...
mikehunt114 Posted July 13, 2007 Share Posted July 13, 2007 That's better than mine, mikehunt114, but I don't see that the line...$colLinks = _IELinkGetCollection($oIE)oÝ÷ Ú·¡ë+ax?ªê-y.ßÚÞ®(!¶ØZ·lçí¢÷«~º&§#¬¦V²x0Øméè®f¥ Bâ@¥ÉÉ7±´²ë"¥¢méÚ×è® -¶^ë^¶¥ªí*W±zs¨¢(¢(¢(¢(¢(¢(¢(¢(¢(¢(¢ zÜ!jܨ»§¶Ú¢z0Iç¢~Øb²¥¦Æ®¶sb6æ6ÇVFRfÇC´RäS2fwC°£´&Æö6´çWB£µ÷VÆFRâ'&vF÷W"FW6&VBÆæ²FWC ¤FÒb33c¶ÆæµFWE³EТ¢b33c¶ÆæµFWE³ÒÒgV÷C´WFòvÆ72V÷FW2gV÷C°¢b33c¶ÆæµFWE³ÒÒgV÷C´WFòvÆ72&W"öVægV÷C°¢b33c¶ÆæµFWE³%ÒÒgV÷CµöVæ¢WFòvÆ72gV÷C°¢b33c¶ÆæµFWE³5ÒÒgV÷C´WFòvÆ72&WÆ6VBgV÷C°¢b33c¶ÆæµFWE³EÒÒgV÷Cµ6fVÆFRWFòvÆ72gV÷C°¢b33c¶ÆæµFWE³UÒÒgV÷C´&6ÖâWFòvÆ72ÄÄ2gV÷C°¢b33c¶ÆæµFWE³eÒÒgV÷C´öff6ÂvV'6FRgV÷C°¢b33c¶ÆæµFWE³uÒÒgV÷CµvæG6VÆB&WÆ6VÖVçBgV÷C°¢b33c¶ÆæµFWE³ÒÒgV÷C´WFòvÆ72õvæG6VÆB&ògV÷C°¢b33c¶ÆæµFWE³ÒÒgV÷CµDrb33·2WFòvÆ72&¦öægV÷C°¢b33c¶ÆæµFWE³ÒÒgV÷CµöVæWFòvÆ72V÷FW2gV÷C°¢b33c¶ÆæµFWE³ÒÒgV÷Cµ7VâFWfÂWFò&W"gV÷C°¢b33c¶ÆæµFWE³%ÒÒgV÷C´&¦öæWFòvÆ72V÷FW2gV÷C°¢b33c¶ÆæµFWE³5ÒÒgV÷Cµ¦öævÆ72gV÷C° ¢b33c·5U$ÂÒgV÷C¶GG¢ò÷wwrævöövÆRæ6öÒ÷6V&6öÃÖVâf×·ÖWFò¶vÆ72·öVæf׶'FäsÕ6V&6gV÷C° ¢b33c¶ôRÒôT7&VFRb33c·5U$¢b33c´täBÒôU&÷W'GvWBb33c¶ôRÂgV÷C¶væBgV÷C²¥vå6WE7FFRb33c´täBÂgV÷C²gV÷C²Â5uôÔÔ¤R¥ôT7Föâb33c¶ôRÂgV÷C·f6&ÆRgV÷C² ¢b33c¶6÷VçBÒ¤f÷"b33c¶ÒFòT&÷VæBb33c¶ÆæµFWBÒ b33c¶õ7öç6÷&VDÆæ·4FbÒôTvWDö&¤'Bb33c¶ôRÂgV÷C·FG2gV÷C²¢b33c¶6Æ6´Ææ²ÒõôTÆæ´6Æ6´'FWBb33c¶õ7öç6÷&VDÆæ·4FbÂb33c¶ÆæµFWE²b33c¶Ò¢bb33c¶6Æ6´Ææ²ÒÓFVâb33c¶6÷VçB³Ò¢ôTæfvFRb33c¶ôRÂb33c·5U$¤æW@¥ôUVBb33c¶ôR £´FÆRb33·2gVæ7FöâvF§W7B7G&ætå7G"6ævP¤gVæ2õôTÆæ´6Æ6´'FWB'&Vbb33c¶õöö&¦V7BÂb33c·5öÆæµFWBÂb33c¶öæFWÒÂb33c¶e÷vBÒ¢bæ÷B4ö&¢b33c¶õöö&¦V7BFVà¢õôTW'&÷$æ÷FggV÷C´W'&÷"gV÷C²ÂgV÷CµõôTÆæ´6Æ6´'FWBgV÷C²ÂgV÷C²b33cµôU7FGW5ôçfÆDFFGRgV÷C²¢6WDW'&÷"b33cµôU7FGW5ôçfÆDFFGR¢&WGW&â¢VæD`¢°¢Æö6Âb33c¶f÷VæBÒÂb33c¶Ææ²Âb33c¶Ææ·FWBÂb33c¶Ææ·2Òb33c¶õöö&¦V7BæFö7VÖVçBæÆæ·0¢b33c¶öæFWÒçVÖ&W"b33c¶öæFW¢f÷"b33c¶Ææ²âb33c¶Ææ·0¢b33c¶Ææ·FWBÒb33c¶Ææ²æ÷WFW%FWBfײgV÷C²gV÷C²²VæBV×G7G&ærFò&WfVçB&ö&ÆVÒvFæò÷WFW%FWBÖvRÆæ·0¢b7G&ætå7G"b33c¶Ææ·FWBÂb33c·5öÆæµFWBFVà¢bb33c¶f÷VæBÒb33c¶öæFWFVà¢b33c¶Ææ²æ6Æ6°¢bb33c¶e÷vBFVà¢ôTÆöEvBb33c¶õöö&¦V7B¢6WDW'&÷"W'&÷"¢&WGW&âÓ¢VæD`¢6WDW'&÷"b33cµôU7FGW5õ7V66W72¢&WGW&âÓ¢VæD`¢b33c¶f÷VæBÒb33c¶f÷VæB²¢VæD`¢æW@¢õôTW'&÷$æ÷FggV÷Cµv&æærgV÷C²ÂgV÷CµõôTÆæ´6Æ6´'FWBgV÷C²ÂgV÷C²b33cµôU7FGW5ôæôÖF6gV÷C²¢6WDW'&÷"b33cµôU7FGW5ôæôÖF6²6÷VÆB&R6W6VB'&ÖWFW""Â2÷"&÷F¢&WGW&â¤VæDgVæ2³ÓÒfwCµôTÆæ´6Æ6´'FW IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font] Link to comment Share on other sites More sharing options...
DaleHohm Posted July 13, 2007 Share Posted July 13, 2007 You're already getting good help from Mike and others on this, so I'm not wanting to detract from that -- only to add some other ideas that will stretch the thinking. The sponsored links at the top of the page have IDs sequentially numbered and starting with "pa", the ones on the side starting with "an". This code will click on each and return for the next... #include <IE.au3> $oIE = _IECreate ("http://www.google.com/search?hl=en&q=auto+glass+phoenix&btnG=Search", 1) $i = 0 While 1 $i += 1 $oLink = _IEGetObjById($oIE, "pa" & String($i)) If @error Then ExitLoop _IEAction($oLink, "click") _IELoadWait($oIE) _IEAction($oIE, "back") WEnd $i = 0 While 1 $i += 1 $oLink = _IEGetObjById($oIE, "an" & String($i)) If @error Then ExitLoop _IEAction($oLink, "click") _IELoadWait($oIE) _IEAction($oIE, "back") WEnd Dale Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model Automate input type=file (Related) Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded Better Better? IE.au3 issues with Vista - Workarounds SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead? Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble Link to comment Share on other sites More sharing options...
Klexen Posted July 14, 2007 Author Share Posted July 14, 2007 (edited) expandcollapse popup#include <IE.Au3> ;Populate an array with your desired link text: Dim $aLinkText[14] While 1 $aLinkText[0] = "Auto Glass Quotes" $aLinkText[1] = "Auto Glass Repair Phoenix" $aLinkText[2] = "Phoenix AZ Auto Glass" $aLinkText[3] = "Auto Glass Replaced" $aLinkText[4] = "Safelite Auto Glass" $aLinkText[5] = "Bachman Auto Glass LLC" $aLinkText[6] = "AAI Official Website" $aLinkText[7] = "Windshield Replacement" $aLinkText[8] = "Auto Glass/Windshield Pro" $aLinkText[9] = "TG's Auto Glass Arizona" $aLinkText[10] = "Phoenix Auto Glass Quotes" $aLinkText[11] = "Sun Devil Auto Repair" $aLinkText[12] = "Arizona Auto Glass Quotes" $aLinkText[13] = "Zona Glass" $pixel2 = 0x7DCF53 $x1y1 = PixelSearch(0,0,@DesktopWidth,@DesktopHeight,$pixel2) MouseMove($x1y1[0],$x1y1[1], 30) MouseClick("right",$x1y1[0],$x1y1[1]) Send("{UP 5}") Send("{ENTER}") $sURL = "http://www.google.com/search?hl=en&q=auto+glass+phoenix&btnG=Search" $oIE = _IECreate($sURL, 1, 0) ;Why not let it try and attach? I see no reason not to wait for the page to load either... $HWND = _IEPropertyGet($oIE, "hwnd") WinSetState($HWND, "", @SW_MAXIMIZE) _IEAction($oIE, "visible") Sleep(5200) $pixel = 0xFFF9DD $xy = PixelSearch(0,0,@DesktopWidth,@DesktopHeight,$pixel) If @error Then _IEQuit($oIE) $pixel2 = 0x7DCF53 $x1y1 = PixelSearch(0,0,@DesktopWidth,@DesktopHeight,$pixel2) MouseMove($x1y1[0],$x1y1[1], 30) MouseClick("right",$x1y1[0],$x1y1[1]) Send("{UP 5}") Send("{ENTER}") Else $count = 0 For $i = 0 To UBound($aLinkText) - 1 $oSponsoredLinksDiv = _IEGetObjById($oIE, "pa" & String($i)) $clickLink = __IELinkClickByText($oSponsoredLinksDiv, $aLinkText[$i]) If $clickLink = -1 Then $count += 1 _IENavigate($oIE, $sURL) $oSponsoredLinksDiv = _IEGetObjById($oIE, "an" & String($i)) $clickLink = __IELinkClickByText($oSponsoredLinksDiv, $aLinkText[$i]) If $clickLink = -1 Then $count += 1 _IENavigate($oIE, $sURL) Next SplashTextOn("Links clicked",$count & " of " & Ubound($aLinkText),100,30) sleep (5000) SplashOff() ConsoleWrite("Number of links clicked succesfully: " & $count & " of " & Ubound($aLinkText) & @CR & @CR) _IEQuit($oIE) EndIf WEnd ;Dale's function with just a StringInStr change Func __IELinkClickByText(ByRef $o_object, $s_linkText, $i_index = 0, $f_wait = 1) If Not IsObj($o_object) Then __IEErrorNotify("Error", "__IELinkClickByText", "$_IEStatus_InvalidDataType") SetError($_IEStatus_InvalidDataType, 1) Return 0 EndIf ; Local $found = 0, $link, $linktext, $links = $o_object.document.links $i_index = Number($i_index) For $link In $links $linktext = $link.outerText & "" ; Append empty string to prevent problem with no outerText (image) links If StringInStr($linktext, $s_linkText) Then If ($found = $i_index) Then $link.click If $f_wait Then _IELoadWait($o_object) SetError(@error) Return -1 EndIf SetError($_IEStatus_Success) Return -1 EndIf $found = $found + 1 EndIf Next __IEErrorNotify("Warning", "__IELinkClickByText", "$_IEStatus_NoMatch") SetError($_IEStatus_NoMatch) ; Could be caused by parameter 2, 3 or both Return 0 EndFunc ;==>_IELinkClickByText Ok, I tried putting that in the code above, but I don't think I did it right. It still clicks links other than Sponsored Links. I would use just the code you have Dale, but it would click all links in the Sponsored, which is pretty much what I want except I don't want it to click on with the text "Phoenix Auto Glass" Is there a way to use that code and exclude that one linktext from being clicked? Thanks again guys for all your help. Edited July 14, 2007 by Klexen Link to comment Share on other sites More sharing options...
DaleHohm Posted July 14, 2007 Share Posted July 14, 2007 (edited) Sorry, I assumed you could put it together from there... removed Dale Edit: You know, I just thought about what it is you are trying to do and decided I really don't want to contribute to it Edited July 14, 2007 by DaleHohm Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model Automate input type=file (Related) Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded Better Better? IE.au3 issues with Vista - Workarounds SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead? Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble Link to comment Share on other sites More sharing options...
Klexen Posted July 14, 2007 Author Share Posted July 14, 2007 Sorry, I assumed you could put it together from there... removed Dale Edit: You know, I just thought about what it is you are trying to do and decided I really don't want to contribute to it 0k well thanks anyway Dale.. Really, thanks. 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