IE Mechanize urls -- what about escaping?

Discussion in 'Perl Misc' started by nsb_tsd@eml.cc, Jun 13, 2006.

  1. Guest

    I am munging together a url from the following snippet of html. It
    shows the button I want to click, except it's accessed thru Javascript.
    The jscript opens a new window which makes the content inaccessible, so
    that's why I want to munge the address myself, so I can open it in the
    same window.

    For munging I extract the key value, append it to the base url, and do
    an IE->get().

    Does IE->get() do url escaping? The key value below is already escaped,
    and I don't know if IE is unescaping the character codes. How would I
    ensure that IE escapes the slashes in the key?

    Thanks!
    nb

    (form code follows)

    <INPUT type=hidden value=%2FxxxD%2Fxxa%2FS%2FasdfF%2Fbsa%2FNI
    L%2FNIL%2FXF%252 name=aname>

    <INPUT
    onclick="JavaScript: myWindow = window.open('Some.jsp?keyvalue=' +
    this.form.aname.value, 'winname', 'width=40, height=10') "
    type=button
    value="Click Me">

    (perl code follows)

    $cnt=$ie->content;
    #print $cnt;
    $reg_str = 'INPUT type=hidden value=(.*) name=aname';
    $cnt =~ qr/$reg_str/;
    $urltogo = $1;
    print "Found! \n==========\n$urltogo\n=========\n";
    $navig_url = 'http://ninjasite:25/abc/';
    #$urltogo =~ s#%2F#/#g;
    $jscript_added = 'Some.jsp?keyvalue=' & $urltogo ;
    $gotou = $navig_url & $jscript_added;
    print "Going to ::$gotou::\n";
    $ie->get($gotou);
    # fails here -- goes to wrong address.
    sleep(12);
    die
    , Jun 13, 2006
    #1
    1. Advertising

  2. J. Gleixner Guest

    wrote:
    > I am munging together a url from the following snippet of html. It
    > shows the button I want to click, except it's accessed thru Javascript.
    > The jscript opens a new window which makes the content inaccessible, so
    > that's why I want to munge the address myself, so I can open it in the
    > same window.
    >
    > For munging I extract the key value, append it to the base url, and do
    > an IE->get().
    >
    > Does IE->get() do url escaping? The key value below is already escaped,
    > and I don't know if IE is unescaping the character codes. How would I
    > ensure that IE escapes the slashes in the key?


    WTF is IE->get???


    > $jscript_added = 'Some.jsp?keyvalue=' & $urltogo ;
    > $gotou = $navig_url & $jscript_added;


    Why are you doing a bitwise and of two scalars??

    > print "Going to ::$gotou::\n";
    > $ie->get($gotou);
    > # fails here -- goes to wrong address.


    Print the value of it and debug from there.
    J. Gleixner, Jun 14, 2006
    #2
    1. Advertising

  3. wrote:

    > I am munging together a url from the following snippet of html. It
    > shows the button I want to click, except it's accessed thru Javascript.
    > The jscript opens a new window which makes the content inaccessible, so
    > that's why I want to munge the address myself, so I can open it in the
    > same window.
    >
    > For munging I extract the key value, append it to the base url, and do
    > an IE->get().
    >
    > Does IE->get() do url escaping? The key value below is already escaped,
    > and I don't know if IE is unescaping the character codes. How would I
    > ensure that IE escapes the slashes in the key?
    > [...]


    Well, you could debug your code by looking if the value is escaped or
    not at any point when the code runs (just for the debug work,
    obviously), like

    print "1. URL is now $urlnow\n";
    print "2. URL is now $urlnow\n";
    ...

    If it turns out you need to unescape the value by hand, it's quite
    easy.

    Perl:
    --------------
    #!perl
    use strict; use warnings; use URI::Escape;
    my $string
    ='2FxxxD%2Fxxa%2FS%2FasdfF%2Fbsa%2FNIL%2FNIL%2FXF%252';
    print uri_unescape($string);
    --------------

    Javascript:
    --------------
    var string =
    '2FxxxD%2Fxxa%2FS%2FasdfF%2Fbsa%2FNIL%2FNIL%2FXF%252'
    document.write(unescape(string))
    --------------

    Hope this helps,

    --
    Bart
    Bart Van der Donck, Jun 14, 2006
    #3
  4. Guest


    > WTF is IE->get???


    Win32::IE::Mechanize object.


    > Why are you doing a bitwise and of two scalars??
    >


    Duh! I thought I was catenating them.
    Good catch!

    > Print the value of it and debug from there.


    Yeah, should have been using plus or dot for string cat.

    Thanks!
    , Jun 14, 2006
    #4
  5. Guest


    > Well, you could debug your code by looking if the value is escaped or
    > not at any point when the code runs (just for the debug work,
    > obviously), like
    >
    > print "1. URL is now $urlnow\n";
    > print "2. URL is now $urlnow\n";
    > ...
    >


    Thanks, I tried that, and saw the %2Fs etc, so I thought it was already
    unescaped.

    The problem turned out to be the misplaced & operator.


    > --------------
    > #!perl
    > use strict; use warnings; use URI::Escape;
    > my $string
    > ='2FxxxD%2Fxxa%2FS%2FasdfF%2Fbsa%2FNIL%2FNIL%2FXF%252';
    > print uri_unescape($string);
    > --------------


    cool, will keep that in mind.

    cheers,
    nb
    , Jun 14, 2006
    #5
  6. Scott Bryce Guest

    wrote:

    > Yeah, should have been using plus or dot for string cat.


    Plus?

    use strict;
    use warnings;

    my $something = 'A';
    my $somethingelse = 'B';

    print 'Using the dot: ', $something . $somethingelse;
    print "\n";

    print 'Using the plus: ', $something + $somethingelse;
    print "\n";

    ---------

    Argument "B" isn't numeric in addition (+) at C:\Scratch\test.pl line 10.
    Using the dot: AB
    Using the plus: 0
    Argument "A" isn't numeric in addition (+) at C:\Scratch\test.pl line 10.
    Scott Bryce, Jun 14, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben

    Escaping ' in Javascript ?

    Ben, Nov 7, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    9,252
    mikeb
    Nov 10, 2003
  2. Kaidi
    Replies:
    5
    Views:
    458
    Andrew Thompson
    Jan 4, 2004
  3. Nathan Sokalski

    Converting Relative URLs into Absolute URLs

    Nathan Sokalski, Aug 11, 2008, in forum: ASP .Net
    Replies:
    1
    Views:
    732
    Sriram Srivatsan
    Aug 12, 2008
  4. Adam Monsen

    JDBC URLs ...not really URLs?

    Adam Monsen, Feb 6, 2009, in forum: Java
    Replies:
    11
    Views:
    6,138
    Adam Monsen
    Feb 8, 2009
  5. Steve T.

    dynamic URLS convert to static URLS for search engines

    Steve T., Mar 1, 2004, in forum: ASP .Net Web Services
    Replies:
    7
    Views:
    276
    Steve T.
    Mar 4, 2004
Loading...

Share This Page