Sign in to follow this  
Followers 0
UNO

Copy text between two words

18 posts in this topic

Hi All,

I have started using AutoIT and trying to create some POC to demonstrate to my co-workers.

However I am stuck at the following level.

Assuming that I have sent some data and clicked "submit" button in a webpage I get some status number/error .When i go to view-->source I see that I it is wrapped around the following line in a very big source file with lot of javascript

<span class="status">&nbsp;&nbsp;I4A50179 : Details are added successfully</span>

I cant let my script to go to view->source coz i dont want the user to see this things happening.

Also I can't search for span coz it gives a lot of instances of finding the source like finding <td colspan="2">

Sometimes the error is displayed with multiple lines of span class code.Then i need them all

Is there any function that can copy text between two words in the down order in a webpage.for eg between text "Loged in as" and "Announcement details"

For example in the same webpage can I copy text between two words.that if possible would include all the status details after the action are performed

Or after view->source how can I make the text file hidden copy the text between "<span class" and "</span>".Please note that sometimes it span multiple lines.

Share this post


Link to post
Share on other sites



If you are using 3.2.2.0

Store the source in a variable with _InetGetSource(), and then look at _StringBetween().


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

If you are using 3.2.2.0

Store the source in a variable with _InetGetSource(), and then look at _StringBetween().

Thanks Smoke .I looked at the help file but i have some queries.

_InetGetSource() Gets the source from an URL without writing a temp file.

#include <INet.au3>

_INetGetSource ( $s_URL )

however I tried to see the url but i have seen that after selecting the value from a dropdown the screen changes.

So i need to capture the current webpage source that is presently displayed.

I can t suppy a static url

Also I cant get the whole text present between Participant ID and Announcement details when i ran the code on the relevent page

Here is the code

$aArray1 = _StringBetween("","Participant ID","Announcement details")

I dont want to search for a particular string but I want to get the text between two words on a webpage.

Share this post


Link to post
Share on other sites

How do you think you get the text between two words? It's a string, you have the first word in the string you want to start at, and the ending part, and it captures everything between.... It does what you asked or better yet, it does what you explained (it being _StringBetween()).

If you have to work with the current page/url, I'd suggest you look at the _IE.au3 and it's functions. And hope that your users aren't using firefox.

GL.


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

IE.au3

LOL, that's twice I've done that this morning (putting an underscore in front of something that didn't need it).

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Hi,

Following is my code

#include <IE.au3>

#include <String.au3>

#include <array.au3>

$oIE = _IEAttach ("General Information");the current version of the web page therefore attach to it

$sText = _IEBodyReadText ($oIE)

$aArray1 = _StringBetween($sText,"<span class=","</span><br>")

MsgBox(0, "Body Text", $aArray1)

;_ArrayDisplay($aArray1, 'Default Search')

_Array display is at all showing up and the script exits and whereas the msgbox is showing 0.

Any ideas where i am going wrong....

Share this post


Link to post
Share on other sites

It returns an array [0] is the first element of the array... just $aArray1 does nothing.

MsgBox(0, "Body Text", $aArray1[0])

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

MsgBox(0, "Body Text", $aArray1[0])

Kurt

EDIT: Damnit! Smoke_N, you always beat me to it!

Edited by _Kurt

Awaiting Diablo III..

Share this post


Link to post
Share on other sites

Got an error when i tried to run the script.

It said

"Error :Subscript used with non-Array variable"

Here is the final code.

#include <IE.au3>

#include <String.au3>

#include <array.au3>

$oIE = _IEAttach ("General Information")

$sText = _IEBodyReadText ($oIE)

$aArray1 = _StringBetween($sText,"<span class=","</span><br>")

MsgBox(0, "Body Text", $aArray1[0])

;_ArrayDisplay($aArray1, 'Default Search')

Where can i going wrong now

Share this post


Link to post
Share on other sites

How about checking how to use Arrays :whistle: ...

#include <IE.au3>
#include <String.au3>
#include <array.au3>

$oIE = _IEAttach ("General Information")
$sText = _IEBodyReadText ($oIE)

$aArray1 = _StringBetween($sText,"<span class=","</span><br>")
If IsArray($aArray1) Then
    MsgBox(0, "Body Text", $aArray1[0])
Else
    MsgBox(0, 'Empty', 'Nothing found')
EndIf

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Hi smoke but i tried that too and it returned "Nothing found"

When i went and viewed the source then it was there

For your refernce pasting a part of the source

<tr>

<td>

<br><span class="error">&nbsp;*&nbsp;E4A345323 : Source Id is Mandatory</span><br>

<br><span class="error">&nbsp;*&nbsp;E4A545345 : Security Id is Mandatory</span><br>

<br><span class="error">&nbsp;*&nbsp;E4454200 : Confirmation Status is Mandatory</span><br>

<script>

Share this post


Link to post
Share on other sites

Works fine for me when I copy what you have and do a FileRead() on it.


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Sometimes I have trouble with _StringBetween, I usually: A) Make the before/after string more accurate B ) Make the before/after string less accurate C) Switch to StringRegExp.

Perhaps try this:

$RegExp = StringRegExp($Source, 'class="error">(.*?)</span>', 3)
Msgbox(0,"",$RegExp[0]

Remember that $RegExp[0] is only the first instance of the pattern. Therefore, if there's 2 of these "patterns" $RegExp[1] would be the second instance.

Kurt

Edited by _Kurt

Awaiting Diablo III..

Share this post


Link to post
Share on other sites

then why am i not getting the code to work on my POC.so far i have succeeded in populating data from excel to the internal application of ours.i have also utilized the excel formulas to generate javascript funcion to populate input text boxes.this is the final thing i want to do i.e get the status which is present in 1 lines or multilines in span read...

Looks like i am stuck and failed by 0.01% in getting the POC to work.Any ideas?I want my place to adopt AutoIT.Many are skecptical and many feel that it may be not be appropriate as it is a freeware.Some fear that they will evetually charge for this freeware in the near future(I dont think so personally after going thru this forum)

1 more issue i am facing........

Also I have trouble getting the Autoit to activate and send keys to the msgbox generated by alert javascript commang for eg typing this code on ur address bar will pop up an alert

java script:alert("UNO");

but when i record and then try to play it back it skips sending enter to this alert.

how can i resolve this too.

Share this post


Link to post
Share on other sites

Thanks Kurt but i cant use the expression that u have provided coz when the data is uploaded successfully then i get another screen but with this code in source

<br><span class="success">&nbsp;*&nbsp;I445455 : Announcement added successfully</span><br>

so i need the data between <br><span class=" and </span><br>(remember it may be multiline in case of failure.)

I will then copy the span class data and then write to the adjaccent new column for status reporting to the excel data file using excelcom.udf

still searching for the answers....

Share this post


Link to post
Share on other sites

@_Kurt, I made _StringBetween() to dummy it down for people really, those that understand StringRegExp() would more than likely not use _StringBetween() as they can be as precise as they like.

@UNO

You are making it difficult to help you. A suggestion would be, provide a link to something similar if not exact, post what you want to find, and maybe someone here can help you. When users ask for help, and make the people that like to help go out of their way to do so, the help either doesn't happen, or eventually stops.

Being explicitly clear in details, step by step in what you are trying to achieve, and providing a snippet, the actual code itself, and all the tools necessary to help you is the best bet in fixing issues.


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Smoke,

I will see if i can find a similar site as the 1 i am working on is an intranet site so i cant get it up from net.

i will post a similar site.i will look 4 it.

i will summarize the problem.

i automatically fill the data from excel to new internal site.

then i click on submit.

based on data i get different notification(they can be multiline also) like on the webpage

*I445455 : Announcement added successfully

or i get error

*E445455 : Field Name missing

*E4434535455 : Field Id missing

*E34577455 : Field Ph missing

a small example that i can think of is the heading 4 this topic of mine on autoit forum

2 User(s) are reading this topic (0 Guests and 0 Anonymous Users)

then it displays name.(right now there are 2 names i.e UNO, GEOSoft)

sometimes it many be none readers ....

or sometimes it may be many readers...

so it is similar to the status of who's reading this post.

I need to copy that info.but 4 my case it embedded in the span tag

for eg

<br><span class="error">&nbsp;*&nbsp;E5Y50098 : Indicator is Mandatory</span><br>

I hope i have thrown some light on this

Share this post


Link to post
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
Sign in to follow this  
Followers 0