Jump to content

Find String in text then take following 5 chars


Recommended Posts

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)


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.


Edited by FillanTroop
Link to comment
Share on other sites


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


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

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



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

Link to comment
Share on other sites

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
Link to comment
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. 


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

  • Recently Browsing   0 members

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