IE Mechanize urls -- what about escaping?

N

nsb_tsd

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
 
J

J. Gleixner

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

Bart Van der Donck

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);
 
N

nsb_tsd

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
 
S

Scott Bryce

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top