views:

98

answers:

4

I want to simulate such clicks without controlling web browsers to do the job. I don't know much about javascript and actually don't know where to start. Any ideas?

+1  A: 

Althoug I have no use it, I think that maybe twill is what you need:

Have a look at this too:

ssoler
+1  A: 

You can use iMacros in combination with Python...

This isn't the most direct solution as it requires you to write an iMacros script to do that actual clicking, and then load the page and call the script from Python.

Refereces:

jcoon
I've been using iMacros for a while, but it's not as stable as I expected, so I kind of want a direct way to do the job. Thanks anyway!
Shane
Still couldn't find a "direct" way, so I guess I will stick with iMacros.
Shane
A: 

If you had control over the link (like adding an ID attribute) you could use javascript to simulate the click

var link = document.getElementById['yourLinksIdAttrbuteValue'];
link.click();

or you could use jQuery selectors as an easy way to better target the link without altering it...

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
<script>
     $(function(){ $("a[href^='javascript']:contains('text')").click() });
</script>

With that code it'll load the JQuery library from google's server, wait for the dom to load, then execute the click.

for more info on jQuery selectors check out http://api.jquery.com/category/selectors/

JKirchartz
Well, I'm actually trying to write a local python script to test the website, so how do I use javascript in python, is there any module to do the job? I don't know much about javascript, so I'm kind of confused right now. Where should I put those script code? What I want is: a local script/program which can simulate a website link clicking without controlling web browsers to do the job, and when I run this script on my computer, the jsp link on that page is clicked. How do I do it? Thanks a lot.
Shane
I'm new to python so I'm not going to be much assistance, I've edited my answer to include all the HTML/javascript you would need to add to a page (assuming they're not using jQuery already, or an incompatible library). Maybe this blog post will help : http://www.sivachandran.in/index.php/blogs/web-automation-using-pyqt4-and-jquery
JKirchartz
A: 

I recommend you take a look at Selenium.

monstru0