Jump to content

_StringInsert() Difficulties


Recommended Posts

Here is a portion of my script:

$sString = _IEBodyReadHTML ($oIE)
$aArray2 = _StringBetween($sString, 'Click on number ', '<br>')
$Click = _StringInsert ( "http://supersecretwebpage.com=", $aArray2, -1)
_IENavigate ($oIE, $Click)

So basically, this will read the source code, set $aArray2 as the string between 'Click on number ' and '<br>' (which is always a number 1 through 12), then I WANT it to navigate to a webpage consisting of "http://supersecretwebpage.com=" with the number at the end.

For example:

Click on number 5

So it would navigate to:

"http://supersecretwebpage.com=5"

Unfortunately, it keeps navigating to "http://supersecretwebpage.com="

Any ideas?

Link to comment
Share on other sites

$aArray2 = _StringBetween($sString, 'Click on number ', '<br>')

$Click = _StringInsert ( "http://supersecretwebpage.com=", $aArray2, -1)

1) See _StringBetween help -- it returns an array. The array is stored in $aArray2. When you want to retrieve an array element you need to use $aArray2[element]. In this case I suspect you will need $aArray2[0].

2) See _StringInsert help -- the -1 will not make the $aArray2[0] go behind the last character in your URL-to-be. To add it behind, you would need to use StringLen("http://supersecretwebpage.com="). But still this is a roundabout way of doing it. Why not just concatenate the two strings? Like:

$Click = "http://supersecretwebpage.com="&$aArray2[0]

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

Actually, I need some help...

$Click = "http://supersecret.com/blah=" & $aArray2[0]

$Click = "http://supersecret.com/blah=" & $aArray2^ ERROR

Error: Subscript used with non-Array variable.

This is the same error that made me abandon the last method I tried using the techniques Sadbunny gave me....

What am I doing wrong?

Sorry if my script is not understandable, ask me any questions you may.

The basic point (or what I want it to do) of this script is so that it loads a website, the

-first IF makes it so that if the website it does not load, it refreshes,

-second IF makes it so that if the website does load, it continues

-third IF makes it so that if it does load, it checks for a string (a variable form value) and uses that to submit the form,

-the fourth IF (a sub-value of the third IF) makes it so that if there is no form to submit, it makes it so that it gets a value presented by the page, and visits a site with that value at the end.

Apparently, this only works when the fourth IF (if there is no form to submit) is true, but then, after it visits the "http://supersecret.com/blah=number", there is a form to submit (which is what I want, so it works) but then I get the error shown above! (I also get the error shown above when I start the script and there IS a form to be submitted.

ARG!

Here's the main chunk....

While $Search = 0
    _IELoadWait ($oIE)
    Global $sString = _IEBodyReadHTML ($oIE)
    If @error then
        Sleep (3000)
        _IENavigate ($oIE, "http://supersecret.com")
        _IEAction ($oIE, "refresh")
        $E = 1
        EndIf
    If not @error then
        $E = 0
        EndIf

    If $E = 0 Then
        Global $aArray = _StringBetween($sString, 'input type=button value="Start Research !" name=', ' onclick=')
        Global $oForm = _IEFormGetObjByName ($oIE, $aArray)
        _IEFormSubmit ($oForm)
        If _IEFormSubmit ($oForm) = 0 Then
            $sString = _IEBodyReadHTML ($oIE)
            $aArray2 = _StringBetween($sString, 'Click on number ', '<br>')
            $Click = "http://supersecret.com/blah=" & $aArray2[0]
            _IENavigate ($oIE, $Click)
            _IELinkClickByText ( $oIE, "Click here to continue")
            _IELinkClickByText ($oIE, "Manage")
            _IELinkClickByText ($oIE, "Research")
            _IENavigate ($oIE, "http://supersecret.com")
            _IEAction ($oIE, "refresh")
            Endif
        Sleep (180000)
        EndIf

WEnd
Link to comment
Share on other sites

Well, a lot of the time _StringBetween doesn't "work" for me when I give it long strings to find. Therefore, instead of using:

Global $aArray = _StringBetween($sString, 'input type=button value="Start Research !" name=', ' onclick=')oÝ÷ Ù:òºÈ§Øb±«­¢+Ù±½°ÀÌØíÉÉäô}MÑÉ¥¹   Ñݸ ÀÌØíÍMÑÉ¥¹°ÌäìÅÕ½Ðì¹µôÌäì°Ìäì½¹±¥¬ôÌäì

Or try different variations, there may be several instances of this one, so try to keep the stuff that other lines most likely wouldn't have. Or, use _ArrayDisplay($YourArray, "") . (requires #include <Array.au3>)

Merely some suggestions,

Kurt

EDIT: 500 Posts!! Woohoo :whistle:

Edited by _Kurt

Awaiting Diablo III..

Link to comment
Share on other sites

Well actually that part works fine, you see, if I remove everything but the fourth IF, the script runs perfectly....

Until it his a spot where there is no form (randomly occurs).

I need it so that when the form is not detected, it does the fourth IF.

Everything is fine except for

$Click = "http://supersecret.com/blah=" & $aArray2[0]

$Click = "http://supersecret.com/blah=" & $aArray2^ ERROR

Error: Subscript used with non-Array variable.

part.

When the form is not present, I need it to:

$sString = _IEBodyReadHTML ($oIE)
$aArray2 = _StringBetween($sString, 'Click on number ', '<br>')
$Click = "http://supersecret.com/blah=" & $aArray2[0]
_IENavigate ($oIE, $Click)
_IELinkClickByText ( $oIE, "Click here to continue")
_IELinkClickByText ($oIE, "Manage")
_IELinkClickByText ($oIE, "Research")
_IENavigate ($oIE, "http://supersecret.com")
_IEAction ($oIE, "refresh")

Even if I substitute that with Check()

and put it as a function outside of the While statement, it still has the same error!

Edited by multiloser
Link to comment
Share on other sites

If you're getting that error, it means that it's not "retrieving" the string between those characters. This means that there are NO instances of the string between 'Click on number ' and '<br>'. It should be relatively easy to solve, mind providing the important part of the source? I could give you suggestions then.

Kurt

Awaiting Diablo III..

Link to comment
Share on other sites

Sorry, I don't think that I'm very good at explaining things.

I get that error when there IS a form, so the fourth IF is NOT supposed to run.

So what happens on my screen is, I see the form, and then the error pops up.

If I didn't see the form, then the IF statement would occur, do as it is supposed to, and then loop back to the beginning, at which point there WOULD be a form, and then it errors.

"If _IEFormSubmit ($oForm) = 0 Then"

Is supposed to make it so that only if there is no form to submit does it check the if statement.

But I still get the error....

Link to comment
Share on other sites

I might as well ask since I have a post already running,

and since this could potentially solve my problem...

If there are three links on a page....

123

213

and

1

Will _IELinkClickByText ($oIE, 1)

Click on the 123 (because it is first link with a 1) or will it click on the 1 (because it is the first/only 1)

Basically, is it character specific? (or whatever)

Exact match?

Link to comment
Share on other sites

  • Moderators

I guess I'll just try it out then?

:D ... :whistle::lmao: ... that might have been a good idea before posting ... no :P ?

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.

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