By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,647 Members | 1,178 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,647 IT Pros & Developers. It's quick & easy.

open links in a html page

P: n/a
Hi,

Using urllib2,ClinetForm and ClinetCookie modules I have logged into my
ISPs web site and managed to fetch the first page. Now, on this page
there is this link:

<a href="#" onclick="check(4);return false;" class="zi01">Service
Records</a>

I need to click this link from python code. How do I do it? check(4) is
the following javascript function:

-------------------------------------------------------------------------------

function check(parameter){
if(parameter==1){
parent.frames(0).location.href="userinfo.jsp" + "?" + new
Date().toString();
}else if(parameter==2){
parent.frames(0).location.href="modipswd.jsp" + "?" + new
Date().toString();
}else if(parameter==3){
parent.frames(0).location.href="cardrecharge.jsp" + "?" +
new Date().toString();
}else if(parameter==4){
parent.frames(0).location.href="serviceRecords.jsp " + "?" +
new Date().toString();
}else if(parameter==5){
parent.frames(0).location.href="rateSelectResult.j sp" +
"?" + new Date().toString();
}
else if(parameter==6){
parent.frames(0).location.href="stopService.jsp" + "?" +
new Date().toString();
}
else if(parameter==7){
if (confirm("Are you sure to exit?")){
window.location="../logout.jsp";
return true;
}else{
return false;
}
}else if(parameter==8){
parent.frames(0).location.href="cancelService.jsp" + "?" +
new Date().toString();
}else{
return false;
}

Aug 16 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"Ajar" <aj********@gmail.com> writes:
Hi,

Using urllib2,ClinetForm and ClinetCookie modules I have logged into my
ISPs web site and managed to fetch the first page. Now, on this page
there is this link:

<a href="#" onclick="check(4);return false;" class="zi01">Service
Records</a>

I need to click this link from python code. How do I do it? check(4) is
the following javascript function:
On way is to have a JavaScript interpreter in your Python
program. Including correctly implementing the DOM to get your sample
right.

-------------------------------------------------------------------------------

function check(parameter){
if(parameter==1){
parent.frames(0).location.href="userinfo.jsp" + "?" + new
Date().toString();
}else if(parameter==2){
parent.frames(0).location.href="modipswd.jsp" + "?" + new
Date().toString();
}else if(parameter==3){
parent.frames(0).location.href="cardrecharge.jsp" + "?" +
new Date().toString();
}else if(parameter==4){
parent.frames(0).location.href="serviceRecords.jsp " + "?" +
new Date().toString();
}else if(parameter==5){
parent.frames(0).location.href="rateSelectResult.j sp" +
"?" + new Date().toString();
}
else if(parameter==6){
parent.frames(0).location.href="stopService.jsp" + "?" +
new Date().toString();
}
else if(parameter==7){
if (confirm("Are you sure to exit?")){
window.location="../logout.jsp";
return true;
}else{
return false;
}
}else if(parameter==8){
parent.frames(0).location.href="cancelService.jsp" + "?" +
new Date().toString();
}else{
return false;
}


The other alternative is to translate the above into Python, and run
that code.

JavaScript lets you do some really cool effects. It pretty much sucks
for any program that wants to read the page, though - your parser,
search engines, etc.

<mike
--
Mike Meyer <mw*@mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
Aug 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.