Sign in to follow this  
Followers 0
FillanTroop

Find String in text then take following 5 chars

8 posts in this topic

#1 ·  Posted (edited)

Hi Guys, 
 
I am going slightly mad of this. Or maybe I am just very tired. :-)
 
There is an www page. Inside of this page is USER ID, but visible only in HTML as ID of the button to display user's profile. It look like this:

<A id=A431_4_011_77168 href='javascript:btnProfile(77168)'>

I have to do two things: 

1. Click that button

2. get the user_ID

Issues: button ID always starts with A431_4_011_ but last 5 numbers are changing, because it is a user ID.  So I can't use: _IEGetObjById neither _IEGetObjByName because there are no wildcards such as * for this type of objects.

So I think how to get that ID. Then I can complete the buttonID and click it.

Shortened version of the code is following: 

If processexists("iexplore.exe") Then
        Local $Ierun = WinActivate ("Internet Explorer")
        Global $IEHUB = _IEAttach ("", "instance",1)
        Local $srchstr = _IEPropertyGet ($IEHUB, "innerhtml")
        Local $st = _StringBetween ($srchstr, "<A id=A431_4_011_", "href='javascript:btnProfile")
        MsgBox($MB_SYSTEMMODAL, "", "" & $st)
        Exit

    EndIf

Apparently, there are two problems. (always comes in couples, bast**ds :-) )

1. I am getting error about expression, because string contains "(" (what is the right way of using these symbols? add them to ' ' ? Or double it? Can't find any explanation on this. 

2. When I am testing it on some other text, the result is always empty. (trying to display it in msgbox)

What am I doing wrong? I am very very new in AutoIt and I have a feeling it should be easy with StringTrim or StringRight, StringSplit, but my experience is very low so far, so I can't find the right way. 

Thank you very much in advance.

Filip 

Edited by FillanTroop

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

FillanTroop,

You can get the number out of your example string like this...

#include<array.au3>

local $str = "<A id=A431_4_011_77168 href='javascript:btnProfile(77168)'>"

local $aRSLT = stringregexp($str,'id=\w+_(\d+)',3)

_arraydisplay($aRSLT)

kylomas

edit:  As to what you are doing wrong, I have no idea.  When I added the correct includes it ran on my PC.  Of course it didn't do anything as the URL for the attach is missing.

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

?

$html = "some html code" & @crlf & _ 
    " <A id=A431_4_011_77168 href='javascript:btnProfile(77168)'>" & @crlf & _ 
    "some other html code"

$ares = StringRegExp($html, '(A431_4_011_\d+)', 1)
Msgbox(0,"", $ares[0])
Edited by mikell

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Thank you very much guys, I really appreciate your help. Just one thing. I cannot test it now, but the problem is that number 77168 in string  <A id=A431_4_011_77168 href='javascript:btnProfile(77168)'> is user ID and it differ for every user. So I don't know it when I am running the script. Will it work?

EDIT: ehm.. ok... i see it now... :-) Thanks... 

Edited by FillanTroop

Share this post


Link to post
Share on other sites

Yes, that is the purpose of the SRE's.  Try it and see if it works....


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

So thanks again, it works and my original script works as well, the key was [0] behind the variable. Can you, please, explain to me, or tell me under which section i can find it in help WHY without the [0] it returns the empty (not zero) string? I assume without it its considered to be some kind of data feed and [0] is actually telling to script to treat variable as string. But I did not found it in help, so I am kind of confused. 

Thanks again, I really appreciate your support and as soon as I gather some experience I'll try to help others as well. 

Filla

Share this post


Link to post
Share on other sites

StringRegExp with flag 1 or 3 returns an array

If there's one result only, you will get an array with one element only, which is in $array[0]

Share this post


Link to post
Share on other sites

Ahhh... ok - THANKS, clear now!  Going to learn about arrays. 

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