开发者

Automate a click of javascript link and fetch the resulting page

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'=12345开发者_StackOverflow6).

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


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜