Jump to content

How To Simulate Click On A Link With Javascrip (using python)?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
7 replies to this topic

#1
shanewang

shanewang

    Newbie

  • Members
  • Pip
  • 3 posts
Hi guys

I'm trying to simulate links clicking on web pages, don't know how to deal with javascript links. The link I'm trying to click contains a tag like this:

<a href="javascript:function(1243423)">text</a>

Would somebody help me out please?

Thanks a lot

Edited by Roger, 26 July 2010 - 02:13 PM.


#2
spyder

spyder

    Programmer

  • Members
  • PipPipPipPip
  • 120 posts
This question should go here.
You will get more traffic to it there.

#3
shanewang

shanewang

    Newbie

  • Members
  • Pip
  • 3 posts

spyder said:

This question should go here.
You will get more traffic to it there.

Maybe the title is a little bit confusing, by "with Javascript" I mean the link contains javascript, and I'm trying to find a solution using python programs, so I guess it's still in the right place. Since you are reading this post, I suppose you may know how to do the job using python?

Thanks

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Are you interacting with a browser, or directly reading the site via python over the web? In the first case, just simulate a click event. In the second case, you'll need to write a JavaScript engine.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#5
shanewang

shanewang

    Newbie

  • Members
  • Pip
  • 3 posts

WingedPanther said:

Are you interacting with a browser, or directly reading the site via python over the web? In the first case, just simulate a click event. In the second case, you'll need to write a JavaScript engine.

Well, actually I don't really know where to start and couldn't find a book teaching such stuff. I've checked a few reference which talks something about how to interact with servers using get/post method, such as:
data=urllib.urlencode(values)
req=urllib2.Request(url, data)
response=urllib2.urlopen(req)

Don't know if I'm on the right way to solve the problem.

My project involves stuff like simulate links clicking and forms submitting etc, and I kind of want them to run in background which means no need to activate browsers such as IE or FF.

I guess it's "directly reading the site via python over the web", right? Sounds like it's harder than simulating a click event?

Is it a must to write a JavaScript engine? And would you mind shedding more light on how to do it?

Thanks a lot for your reply!

#6
spyder

spyder

    Programmer

  • Members
  • PipPipPipPip
  • 120 posts

shanewang said:

Maybe the title is a little bit confusing, by "with Javascript" I mean the link contains javascript, and I'm trying to find a solution using python programs, so I guess it's still in the right place. Since you are reading this post, I suppose you may know how to do the job using python?

Thanks

I do use Python on a regular basis, and JavaScript fairly often too, but unfortunately I do not use urllib too much, so I have not done too much.
I went to this post out of curiosity, but if you explain your problem a little bit more, I could possibly be able to help. :)
Sorry if I can't help. ^^
I C!(and Python, and C++, and ...)

#7
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
It sounds like you will need to correctly parse the javascript to simulate clicking the link. I don't know if there are any javascript interpreters written in python or not, but I'd start by searching for those. Standard disclaimer: I am NOT a python programmer.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#8
Excited

Excited

    Newbie

  • Members
  • PipPip
  • 27 posts
Look into those javascript functions and make a parser to get the data needed to construct the actual post request.