views:

46

answers:

2

Hi all,

I searched a lot but could not find a solution for my question. It is quite simple as I think.

I opened a web page by providing some parameters, such as id=123456. The searched result page then contains a link to something like javascript:doSomething('ABC','ID'=123456).

What I would like to know, is whether there is a program, in perl, python, java, c, whatever, that could take an id as a parameter, and automatically click the javascript link, and fetch the content of the resulting page.

Do you have a solution to this problem?

Thanks a lot!

Frank

A: 

You can simulate the DOM click event:

function ClickID(id) {
    var event = document.createEvent('MouseEvents');
    event.initEvent( 'click', true, true );
    document.getElementById(id).dispatchEvent(event);
}
Delan Azabani
Hi NullUserException, I'm not trying to scrape the page. It contains millions of records, and I am trying to fetch hundreds without manual click.
frank
Hi Delan Azabani, Thanks a lot for your answer. Unfortunately I know just a little of javascript. Looks like your code is a javascript code. Do I then have to open a webpage containing this piece of code? How could I use a program to get the data? Sorry for this type of dumb questions. Also, it looks to me I need to provide the id of the click element. Unfortunately the page does not seem to have it. Here is the page source: <td width="65" align="center"><a href="javascript:doSomthing('ABC', '1234567')" class="a02">Click_Showname</a></td> Any idea? Thanks! -Frank
frank
A: 

This is not the correct answer to my general question, but did resolve my problem. So I am posting what I did, and hope to help others if they face the same issue.

Basically I worked around the javscript. I looked in the source of the pages, and found some hidden parameters. The about 300 char parameters, that I thought were un-predictable, were there! So I grabbed the value using mechanize and browse a new url using the parameter, and bingo, it works!

So my experience is to look at the source of the page, and do some guesses.

frank