Jump to content

Win Get Text


Recommended Posts

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

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

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

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

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 by stampy
Link to comment
Share on other sites

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 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

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

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

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?

MouseClick("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) 

Exit

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)

Link to comment
Share on other sites

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

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 :D

MouseClick("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 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

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

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 at

i 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

@Jack go drink a beer... your going to hurt yourself :D

@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

#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

.

Link to comment
Share on other sites

@Jack go drink a beer... your going to hurt yourself

well 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 :D

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

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 :D

@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

Whats_Styles_Is_Doing.pdf

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...