styles3000 Posted May 31, 2009 Share Posted May 31, 2009 Hello Ladies and gents, I need your assistance. What I'm doing is going within documents and extracting text from in between tags. <title>Lg Ku990 Viewty Room For A View</title>The problem is that at times AutoIT selects only part of the text at times;then to much of the text( goes past the ending tag), or just short of the ending tag. What kind of function can I call that will extract all text in between the tags? I need a funtion that knows when I WinWait( ) and it sees the opening and closing tags <title>.......</title> ,the whole string in between those tags is to be extracted no matter how long or short the string is. An associate of mine says to write a function to look for the tag I look for the markers... then go to then next marker to copy. He says, I doesn't believe there is an AutoIT function that just does it. He says ,I should could check for the '>' and just copy everything till I get to a '<' then don't start again until you get to another '>'. He says I'll pretty much have to parse it character by character, but it will work. I don't know where to start. Link to comment Share on other sites More sharing options...
stampy Posted May 31, 2009 Share Posted May 31, 2009 Something along these lines? $x = '<title>Lg Ku990 Viewty Room For A View</title>' $posStart = StringInStr($x,'<title>')+7 $posEnd = StringInStr($x,'</title>') $result = StringMid($x,$posStart,$posEnd-$posStart) MsgBox(0,'',$result) Link to comment Share on other sites More sharing options...
styles3000 Posted May 31, 2009 Author Share Posted May 31, 2009 I'll be using this function to process many documents with different titles of different length. Is this function applicable to any document that have title tags ? If not, how can I make the function that knows that as soon as it opens that document its in between the open and close <title> tags to be selected and copied and not just when it sees 'Lg Ku990 Viewty Room For A View'. Something along these lines? $x = '<title>Lg Ku990 Viewty Room For A View</title>' $posStart = StringInStr($x,'<title>')+7 $posEnd = StringInStr($x,'</title>') $result = StringMid($x,$posStart,$posEnd-$posStart) MsgBox(0,'',$result) Link to comment Share on other sites More sharing options...
Roman9 Posted May 31, 2009 Share Posted May 31, 2009 I'll be using this function to process many documents with different titles of different length. Is this function applicable to any document that have title tags ? If not, how can I make the function that knows that as soon as it opens that document its in between the open and close <title> tags to be selected and copied and not just when it sees 'Lg Ku990 Viewty Room For A View'.As you can see by the code (I hope ), this selects any text located in between <title> and </title>Example:<title>My site</title>Would return "My site" Link to comment Share on other sites More sharing options...
Pain Posted May 31, 2009 Share Posted May 31, 2009 What's wrong with _StringBetween? You don't have to reinvent the wheel Link to comment Share on other sites More sharing options...
styles3000 Posted May 31, 2009 Author Share Posted May 31, 2009 What's wrong with _StringBetween? You don't have to reinvent the wheel Hey Pain, The more the merrier. Maybe one does one thing that the other doesn't . My next question is how to place the function. Now that I'm assured that it does take all the content within the tags. I'm guessing that which was copied will be stored in the clipboard so all I'll have to do is send the command to paste right?'send(^v)' So it should look like this below........ MouseMove(293,13)sleep(3000)MouseDown("left")MouseUp("left")WinWait("classname=Shell_TrayWnd","TF_FloatingLangBar_W")If Not WinActive("classname=Shell_TrayWnd","TF_FloatingLangBar_W") Then WinActivate("classname=Shell_TrayWnd","TF_FloatingLangBar_W")WinWaitActive("classname=Shell_TrayWnd","TF_FloatingLangBar_W")MouseMove(414,15)sleep(3000)MouseDown("left")MouseUp("left")MouseMove(406,-37)sleep(3000)MouseDown("left")MouseUp("left")WinWait("lg - Notepad","")If Not WinActive("lg - Notepad","") Then WinActivate("lg - Notepad","")WinWaitActive("lg - Notepad","")Send("{CTRLDOWN}v{CTRLUP}{ENTER}{ENTER}{ENTER}");Right here is where I need that that which was selected between the tags placed here, in the place of the send function. How could a brotha do this? Would I use use send(^V) to paste it?WinWait("classname=Shell_TrayWnd","TF_FloatingLangBar_W")If Not WinActive("classname=Shell_TrayWnd","TF_FloatingLangBar_W") Then WinActivate("classname=Shell_TrayWnd","TF_FloatingLangBar_W")WinWaitActive("classname=Shell_TrayWnd","TF_FloatingLangBar_W")MouseMove(436,13)sleep(3000)MouseDown("left")MouseUp("left")MouseMove(587,9)sleep(3000)MouseDown("left")MouseUp("left") Link to comment Share on other sites More sharing options...
MDCT Posted June 1, 2009 Share Posted June 1, 2009 I think ControlSend is better than normal mouse move & click. The window doesn't have to be active to click a control and it's not restricted to a certain coordinate of the screen.Here: http://www.autoitscript.com/autoit3/docs/f...ControlSend.htmGood luck. Link to comment Share on other sites More sharing options...
stampy Posted June 1, 2009 Share Posted June 1, 2009 (edited) a) Nothing is wrong with _stringbetween use it if you like. I didn't think 3 lines of code was a big deal... I can rewrite it into one if you'd like. $result = StringMid($x,StringInStr($x,'<title>')+7,StringInStr($x,'</title>')-StringInStr($x,'<title>')+7) b ) I agree controlsend is better to use if the window has controls it will work with. c) In the relative code that was shown before $x = '<title>Lg Ku990 Viewty – Room For A View</title>' $posStart = StringInStr($x,'<title>')+7 $posEnd = StringInStr($x,'</title>') $result = StringMid($x,$posStart,$posEnd-$posStart) MsgBox(0,'',$result) the """ $result """ variable contains the information. The clipboard does not. To send a variable simply ... Send($result) Edited June 1, 2009 by stampy Link to comment Share on other sites More sharing options...
JackDinn Posted June 1, 2009 Share Posted June 1, 2009 (edited) personally would use StringRegExp(). especially if you string contains many tags that you want to get individually. $String = "<title>Lg Ku990 Viewty – Room For A View</title> sca <title>test2</title>" $result = StringRegExp($String, "<title>(.+?)</title>", 3) for $x=0 to Ubound($result)-1 MsgBox(0,'',$result[$x]) Next p.s. hi , didn't you post in the Yahoo groups ? or is it just a coincidence Edited June 1, 2009 by JackDinn Thx all,Jack Dinn. JD's Auto Internet Speed Tester JD's Clip Catch (With Screen Shot Helper) Projects :- AutoIt - My projects My software never has bugs. It just develops random features. :-D Link to comment Share on other sites More sharing options...
styles3000 Posted June 1, 2009 Author Share Posted June 1, 2009 personally would use StringRegExp(). especially if you string contains many tags that you want to get individually. $String = "<title>Lg Ku990 Viewty Room For A View</title> sca <title>test2</title>" $result = StringRegExp($String, "<title>(.+?)</title>", 3) for $x=0 to Ubound($result)-1 MsgBox(0,'',$result[$x]) Next p.s. hi , didn't you post in the Yahoo groups ? or is it just a coincidence Yes, I did. But I didn't get the same results as here. Link to comment Share on other sites More sharing options...
JackDinn Posted June 1, 2009 Share Posted June 1, 2009 Yes, I did. But I didn't get the same results as here.tehe, well you did get the StringRegExp() method , as i posted it but as with most things in AI there are quite often several different ways to do the same thing, none are wrong, if they work, but some might be just a little more efficient than others.but anyhow good to see you decided to join the AutoIt forum a lot better than the Yahoo groups , welcome . Thx all,Jack Dinn. JD's Auto Internet Speed Tester JD's Clip Catch (With Screen Shot Helper) Projects :- AutoIt - My projects My software never has bugs. It just develops random features. :-D Link to comment Share on other sites More sharing options...
styles3000 Posted June 2, 2009 Author Share Posted June 2, 2009 When I used this one, autoit didn't paste any of the string from within the tags. The only thing it pasted was the number zero . What could be the problem? expandcollapse popupMouseClick("left",239,148,2);This is where the document opens up. WinWait("lg0001 - Notepad","") If Not WinActive("lg0001 - Notepad","") Then WinActivate("lg0001 - Notepad","") WinWaitActive("lg0001 - Notepad","") $x = '<title>Lg Ku990 Viewty Room For A View</title>' $result = StringRegExp($x,StringInStr($x,'<title>')+7,StringInStr($x,'</title>')-StringInStr($x,'<title>')+7) MouseMove(270,13);This is where the cursor moves over the maximize button. MouseDown("left") MouseUp("left") MouseMove(767,16) ;------------------------------------------------------------------- ;$String = "<title>Lg Ku990 Viewty Room For A View</title> sca <title>test2</title>" ;$result = StringRegExp($String, "<title>(.+?)</title>", 3) ;for $x=0 to Ubound($result)-1 ;MsgBox(0,'',$result[$x]) ;Next ;----------------------------------------------- ;$x = '<title>Lg Ku990 Viewty Room For A View</title>' ;$posStart = StringInStr($x,'<title>')+7 ;$posEnd = StringInStr($x,'</title>') ;$result = StringMid($x,$posStart,$posEnd-$posStart) ;MsgBox(0,'',$result) ;------------------------------------------------------------- MouseDown("left") MouseUp("left") ;Idea:Look into a funtion finds the 2 tags <title> and </title> that counts ;Send("$result") MouseMove(292,14) MouseDown("left") MouseUp("left") WinWait("classname=Shell_TrayWnd","TF_FloatingLangBar_W") If Not WinActive("classname=Shell_TrayWnd","TF_FloatingLangBar_W") Then WinActivate("classname=Shell_TrayWnd","TF_FloatingLangBar_W") WinWaitActive("classname=Shell_TrayWnd","TF_FloatingLangBar_W") MouseMove(429,14) sleep(3000) MouseDown("left") MouseUp("left") MouseMove(426,-35) MouseDown("left") MouseUp("left") WinWait("lg - Notepad","") If Not WinActive("lg - Notepad","") Then WinActivate("lg - Notepad","") WinWaitActive("lg - Notepad","") Send($result) Exita) Nothing is wrong with _stringbetween use it if you like. I didn't think 3 lines of code was a big deal... I can rewrite it into one if you'd like. $result = StringMid($x,StringInStr($x,'<title>')+7,StringInStr($x,'</title>')-StringInStr($x,'<title>')+7) b ) I agree controlsend is better to use if the window has controls it will work with. c) In the relative code that was shown before $x = '<title>Lg Ku990 Viewty Room For A View</title>' $posStart = StringInStr($x,'<title>')+7 $posEnd = StringInStr($x,'</title>') $result = StringMid($x,$posStart,$posEnd-$posStart) MsgBox(0,'',$result) the """ $result """ variable contains the information. The clipboard does not. To send a variable simply ... Send($result) Link to comment Share on other sites More sharing options...
stampy Posted June 2, 2009 Share Posted June 2, 2009 This doesn't work. $result = StringRegExp($x,StringInStr($x,'<title>')+7,StringInStr($x,'</title>')-StringInStr($x,'<title>')+7)oÝ÷ Ù+kx+kÇâØ§ªh²+b¢|!Èb±©î·«b««â®)àEèÆâÛazµêç¡ö¬x%z{¦mêÖ'!×hzÉèíê+§jT®)àEèÆ!¢é]Âä~ò¢ëa¢è!jëh×6$result = StringRegExp($String, "<title>(.+?)</title>", 3) for $x=0 to Ubound($result)-1 sgBox(0,'',$result[$x]) Next Link to comment Share on other sites More sharing options...
JackDinn Posted June 2, 2009 Share Posted June 2, 2009 (edited) ooo, where did you get that from? $result = StringRegExp($x,StringInStr($x,'<title>')+7,StringInStr($x,'</title>')-StringInStr($x,'<title>')+7) its like a random mixture of all the suggestions you have been given so far expandcollapse popupMouseClick("left",239,148,2);This is where the document opens up. WinWait("lg0001 - Notepad","") If Not WinActive("lg0001 - Notepad","") Then WinActivate("lg0001 - Notepad","") WinWaitActive("lg0001 - Notepad","") $x = '<title>Lg Ku990 Viewty – Room For A View</title>' $result = StringRegExp($String, "<title>(.+?)</title>", 3); ********** like this MouseMove(270,13);This is where the cursor moves over the maximize button. MouseDown("left") MouseUp("left") MouseMove(767,16) ;------------------------------------------------------------------- ;$String = "<title>Lg Ku990 Viewty – Room For A View</title> sca <title>test2</title>" ;$result = StringRegExp($String, "<title>(.+?)</title>", 3) ;for $x=0 to Ubound($result)-1 ;MsgBox(0,'',$result[$x]) ;Next ;----------------------------------------------- ;$x = '<title>Lg Ku990 Viewty – Room For A View</title>' ;$posStart = StringInStr($x,'<title>')+7 ;$posEnd = StringInStr($x,'</title>') ;$result = StringMid($x,$posStart,$posEnd-$posStart) ;MsgBox(0,'',$result) ;------------------------------------------------------------- MouseDown("left") MouseUp("left") ;Idea:Look into a funtion finds the 2 tags <title> and </title> that counts ;Send("$result") MouseMove(292,14) MouseDown("left") MouseUp("left") WinWait("classname=Shell_TrayWnd","TF_FloatingLangBar_W") If Not WinActive("classname=Shell_TrayWnd","TF_FloatingLangBar_W") Then WinActivate("classname=Shell_TrayWnd","TF_FloatingLangBar_W") WinWaitActive("classname=Shell_TrayWnd","TF_FloatingLangBar_W") MouseMove(429,14) sleep(3000) MouseDown("left") MouseUp("left") MouseMove(426,-35) MouseDown("left") MouseUp("left") WinWait("lg - Notepad","") If Not WinActive("lg - Notepad","") Then WinActivate("lg - Notepad","") WinWaitActive("lg - Notepad","") Send($result[0]); ********* and this , although this is only the first tags content but i hope its ok Exit Edited June 2, 2009 by JackDinn Thx all,Jack Dinn. JD's Auto Internet Speed Tester JD's Clip Catch (With Screen Shot Helper) Projects :- AutoIt - My projects My software never has bugs. It just develops random features. :-D Link to comment Share on other sites More sharing options...
styles3000 Posted June 2, 2009 Author Share Posted June 2, 2009 Hey Fella, So far this the one thats the most promising. $x = '<title>Lg Ku990 Viewty Room For A View</title>' $posStart = StringInStr($x,'<title>')+7 $posEnd = StringInStr($x,'</title>') $result = StringMid($x,$posStart,$posEnd-$posStart) MsgBox(0,'',$result) The only problem is that it only extracts and pastes 'Lg Ku990 Viewty Room For A View' over and over again. I place the function after another document(the 2nd) called........................ <title>It's Finally Here... The Lg Ks 360</title> just to test and see if the function will extract and paste it. But and it still outputs the 1st one which was 'Lg Ku990 Viewty Room For A View'. I feel something needs to be adjusted here...$x = '<title>Lg Ku990 Viewty Room For A View</title>' So it doesn't always output 'Lg Ku990 Viewty Room For A View' for every document. Link to comment Share on other sites More sharing options...
JackDinn Posted June 2, 2009 Share Posted June 2, 2009 look you dont leave the $x = '<title>Lg Ku990 Viewty Room For A View</title>' line in there and expect it to work, this line is just a demonstration line to try to show you how it might work. your supposed to get the string from where ever or what ever you want to look ati just feel im banging my head against a brick wall, you really are not getting it & it's not for lack of us trying.o im sorry, please dont take it personally but perhaps someone else can take it from here please ! Thx all,Jack Dinn. JD's Auto Internet Speed Tester JD's Clip Catch (With Screen Shot Helper) Projects :- AutoIt - My projects My software never has bugs. It just develops random features. :-D Link to comment Share on other sites More sharing options...
stampy Posted June 2, 2009 Share Posted June 2, 2009 @Jack go drink a beer... your going to hurt yourself @Styles... Where are you getting the <title></title > tags from? At this point we are only declaring them in their own variable for testing purposes. But in the end we need to "READ" them from somewhere. Is this coming from a file? a web page? another window? Once we "READ" that information we can put that into a variable and use it. Then "READ" the next one then use that... etc ... etc Link to comment Share on other sites More sharing options...
DCCD Posted June 2, 2009 Share Posted June 2, 2009 #include <Inet.au3> ; $array = StringRegExp(_INetGetSource("http://www.autoitscript.com/forum/index.php?showtopic=95962"), '<(?i)title>(.*?)</(?i)title>', 1) ; for $i = 0 to UBound($array) - 1 msgbox(0, "GetTitle", $array[$i]) Next . [u][font=Arial Black]M[/font]y Blog, AVSS Parts[/u][font=Arial Black]Else[/font][font=Arial Black]L[/font]ibya Linux Users Group Link to comment Share on other sites More sharing options...
JackDinn Posted June 2, 2009 Share Posted June 2, 2009 @Jack go drink a beer... your going to hurt yourselfwell had 2 beers , buuurrrpp... cheers all, now im of to bed, good luck with this one all, maybe this thread will be sorted by the time i get up in the morning night. Thx all,Jack Dinn. JD's Auto Internet Speed Tester JD's Clip Catch (With Screen Shot Helper) Projects :- AutoIt - My projects My software never has bugs. It just develops random features. :-D Link to comment Share on other sites More sharing options...
styles3000 Posted June 2, 2009 Author Share Posted June 2, 2009 My bad, Jack. Thanks for your patience stampy. I uploaded a pdf of where the tags are coming from.. stampy @Jack go drink a beer... your going to hurt yourself @Styles...Where are you getting the <title></title > tags from? At this point we are only declaring them in their own variable for testing purposes. But in the end we need to "READ" them from somewhere. Is this coming from a file? a web page? another window? Once we "READ" that information we can put that into a variable and use it. Then "READ" the next one then use that... etc ... etcWhats_Styles_Is_Doing.pdf 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