open links in a html page

A

Ajar

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.jsp" +
"?" + 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;
}
 
M

Mike Meyer

Ajar said:
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.jsp" +
"?" + 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
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top