Find and slice problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jont999@yahoo.co.uk

    #1

    Find and slice problem

    Hi guys, been going around in circles with this so I hope you can help!

    My current situation is I'm using Grinder and Jython to test pages, but
    the log on process is giving me some headaches. After entering the
    correct username and password, you then need to enter 3 characters from
    the security phrase. I'm attempting to read the HTML to find out with
    characters I need (e.g. 1st, 3rd and 6th char) then look up those
    values in the security phrase, but I'm getting stuck on the following
    function:

    <code>

    def getValue(page,d elimEnd) :
    EndVar = page.find(delim End)
    thisVar = page[EndVar-1:EndVar]
    return thisVar

    </code>

    <unique code I'm using as a delimeter>
    :</strong></td>
    <td class="productt ableinnerborder "></td>
    <td></td>

    <td><select name="char1">
    </unique code I'm using as a delimeter>

    the specific number I require proceeds the ':' at the start of the
    code.

    What I'm attemping to pass in is some multiline HTML(above) and pick up
    the proceeding character, but it seems to be reading from the end of
    the HTML instead! I've only been using this setup for a couple of days
    so it's probably something simple, anyone care to enlighten me?

    cheers,

    Jon

  • Juho Schultz

    #2
    Re: Find and slice problem

    jont999@yahoo.c o.uk wrote:[color=blue]
    > Hi guys, been going around in circles with this so I hope you can help!
    >
    > My current situation is I'm using Grinder and Jython to test pages, but
    > the log on process is giving me some headaches. After entering the
    > correct username and password, you then need to enter 3 characters from
    > the security phrase. I'm attempting to read the HTML to find out with
    > characters I need (e.g. 1st, 3rd and 6th char) then look up those
    > values in the security phrase, but I'm getting stuck on the following
    > function:
    >
    > <code>
    >
    > def getValue(page,d elimEnd) :
    > EndVar = page.find(delim End)
    > thisVar = page[EndVar-1:EndVar]
    > return thisVar
    >
    > </code>
    >
    > What I'm attemping to pass in is some multiline HTML(above) and pick up
    > the proceeding character, but it seems to be reading from the end of
    > the HTML instead![/color]

    page.find(delim End) returns -1 if delimEnd is not found, and after that
    you take page[-2:-1], i.e. second last character.

    So you could add a test for that, if EndVar == -1 etc.
    but I recommend using page.index(deli mEnd) which raises an error if
    delimEnd is not found.

    Comment

    Working...