open links in a html page

Mike Meyer mwm at mired.org
Tue Aug 16 22:34:19 EDT 2005


"Ajar" <ajartaknev at 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.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
-- 
Mike Meyer <mwm at mired.org>			http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.



More information about the Python-list mailing list