开发者

How to simulate clicks on <a href="javascript:dosomething(12345)">text</a> using python? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.

Want to improve this question? Update the question so it focuses on one problem only by editing this post.

Closed 3 years ago.

Improve this question

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?


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

  • twill: a simple scripting language for Web browsing

Have a look at this too:

  • Testing Web Applications with Python and Twill


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:

  • iMacros CLICK command
  • iMacros wiki


I recommend you take a look at Selenium.


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/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜