kctvt Posted February 1, 2011 Share Posted February 1, 2011 (edited) Hi there, I got some problem in get the true link from IE. So I need help.I have about 50 links and more in site, but I only want to get about 5 links.Now, there're a few links.http://www.hulahula.com/album.php?profile=1&id=100001441852798http://www.hulahula.com/franchelinkhttp://www.hulahula.com/franchelink?sk=list&v=listhttp://www.hulahula.com/franche.christ/news/149199628471431http://www.hulahula.com/profile.php?id=1275759374http://www.hulahula.com/profile.php?id=100000089022254http://www.hulahula.com/franche.christ/news/159195624472487http://www.hulahula.com/permalink.php?numid=149179445140116&id=100001988032272First , I plan to use : $link1 = _IELinkGetCollection ($oIE,1) $link2 = _IELinkGetCollection ($oIE,2)to get Link from IE. Then :$Number = number ;;;; Problem right here !!! IF $link1 = ("http://www.hulahula.com/franche.christ/news/"&$Number) then Msgbox (48, "Note", "True link" ,100) EndIFProblem is... I dont know how to the code understand I only want to get links like "http://www.hulahula.com/franche.christ/news/"+ Number So... I need help @_@ Edited February 1, 2011 by kctvt Link to comment Share on other sites More sharing options...
Steveiwonder Posted February 1, 2011 Share Posted February 1, 2011 (edited) Try something like.You should probably take a look at Regular Expressions.$oLinks =_IELinkGetCollection($oIE) For $oLink in $oLinks if StringInStr($oLink.href, "http://www.hulahula.com/franche.christ/news/") Then ConsoleWrite("Link Found: " & $oLink.href & @CRLF) EndIf Next Edited February 1, 2011 by Steveiwonder They call me MrRegExpMan Link to comment Share on other sites More sharing options...
kctvt Posted February 1, 2011 Author Share Posted February 1, 2011 Oh... Thanks so much Steveiwonder It's working. But , I got a new problem =.= After this code run $oLinks =_IELinkGetCollection($oIE) For $oLink in $oLinks if StringInStr($oLink.href, "http://www.hulahula.com/franche.christ/news/") Then ConsoleWrite("Link Found: " & $oLink.href & @CRLF) EndIf Next There are some links I had before. I dont want take them again. So, I creat a log file (Log.txt) How can I make this code dont take these logged links Link to comment Share on other sites More sharing options...
Steveiwonder Posted February 2, 2011 Share Posted February 2, 2011 (edited) Something like this $oLinks =_IELinkGetCollection($oIE) For $oLink in $oLinks if StringInStr($oLink.href, "http://www.hulahula.com/franche.christ/news/") Then $fileContent = FileRead("Log.txt") ; called here so that you can save link to new log and then reload so it doesn't duplicate a link If NOT StringInStr($fileContent, $olink.href) Then ; Link doesn't exist in file? ConsoleWrite("Link Found: " & $oLink.href & @CRLF) ;do savestuff here EndIf EndIf Next Edited February 2, 2011 by Steveiwonder They call me MrRegExpMan Link to comment Share on other sites More sharing options...
GEOSoft Posted February 2, 2011 Share Posted February 2, 2011 Is it just the links in red that you want? If so then you don't really even need the link collection just the page source.$sSrc = BinaryToString(InetRead("http:\\www.hulahula.com")) If NOT @Error Then $aValidLinks = StringRegExp($sSrc, "(http:\S+christ/news/\d+|http:\S+php\?numid=[id=&\d]+)", 3);; 0 based array If NOT @Error Then For $i = 0 To Ubound($aValidLinks) -1 MsgBox(0, "Valid Result " & $i+1, $aValidLinks[$i]) Next EndIf EndIfIf You still want to use the collection then use the same RegExp like this$oLinks =_IELinkGetCollection($oIE) For $oLink in $oLinks If NOT StringRegExp($oLink, "(http:\S+christ/news/\d+|http:\S+php\?numid=[id=&\d]+)") Then ContinueLoop Else ;; Do what you want with the link here EndIf NextNOTE: Written on the fly with only the expression tested using PCRE Toolkit against the examples and assuming the links in red are what you want. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
kctvt Posted February 4, 2011 Author Share Posted February 4, 2011 (edited) umm... This is my new code. Check it $Links = _IELinkGetCollection ($oIE) For $Link in $Links If StringInStr($Link.href,"http://www.hulahula.com/franche.christ/news/") then $fileContent = FileRead("LogLink.txt") If StringInStr($fileContent, $Link.href) then ConsoleWrite("Old Link Found : " &$Link.href & @CRLF) Else _IEAction ($Link,"click") _IELoadWait ($oIE) $Text = _IEBodyReadText ($oIE) $URLnow = _IEPropertyGet ($oIE,"locationurl") Select Case StringInStr($Text, "CALL-Bumba") Msgbox (48, "Notice","Calling Bumba" ,5) _ArrayAdd ($LinkText,$URLnow) _FileWriteFromArray("LogLink.txt",$LinkText, 1) _IENavigate ($oIE,"http://www.hulahula.com/franche.christ/") _IELoadWait ($oIE) Case Else Msgbox (48, "Notice","Saving error link" ,5) _ArrayAdd ($LinkText,$URLnow) _FileWriteFromArray("LogLink.txt",$LinkText, 1) _IENavigate ($oIE,"http://www.hulahula.com/franche.christ/") _IELoadWait ($oIE) EndSelect EndIf EndIf Next It works very good with the first link "http://www.hulahula.com/franche.christ/news/197894253559137" But, when the second link run , this code dont work. Autoit said that : ==> The requested action with this object has failed.: If StringInStr($Link.href,"http://www.hulahula.com/franche.christ/news/") then If StringInStr($Link.href^ ERROR Something wrong ? Edited February 4, 2011 by kctvt Link to comment Share on other sites More sharing options...
PsaltyDS Posted February 4, 2011 Share Posted February 4, 2011 The $Links collection is only valid in that document. Once you do _IEAction($Link, "click") a new document is loaded and all the object references in the $Links collection become invalid. 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...
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