0

I have a page full of links like this:

<a href="javascript:Window('args')"> text here </a>

When the link is clicked a window pops up (using Javascript). The Javascript also creates the contents of the new window. (with innerHTML)

The content consists of a form like this:

<form method="post" action="/doaction.php">
    <input type="hidden" value="hashcode">
    /* code to insert data (textfields etc.) */
    <input type="submit">
</form>

What i'm trying to do is:

  1. Filter all the links i need
  2. clicking the first link to open the popup window
  3. clicking the submit button to send the data

The first step shouldn't be to hard and i can figure that out myself.
However i have no clue how to do step 2 (but i can probably find some tutorials on how to click a link in Python) and step 3.

So any help on how to start with step 3 is highly appreciated.

(Also if i really shouldn't be doing this in Python, let me know)

3
  • Urgh. There's no reason to use the javascript: pseudo-protocol in HTML links these days. Leave the href empty and use onclick instead. Commented Jan 4, 2011 at 20:04
  • 1
    @Daniel I assume it is not a page the OP has written :) Commented Jan 4, 2011 at 20:09
  • 1
    @Ashy you're completely right :) Commented Jan 5, 2011 at 10:40

1 Answer 1

5

You can use urllib2.urlopen to make a POST request to the script the form is submitting to.

import urllib, urllib2
url = '/doaction.php'
data= {'hashcode': 'blah', 'name':'blahblah', 'type':'blahblahblah'}
request = urllib2.Request(url, urllib.urlencode(data))
response = urllib2.urlopen(request)
Sign up to request clarification or add additional context in comments.

2 Comments

Ok, that looks managable. I can't find any info on the syntax for the data string. Let's say i have 3 inputs with values: "hashcode", "name", "type", how would my data string look like ? The link you provided says it has to be a buffer in the application/x-www-form-urlencoded format, but i have no clue what that means.
You can use urlencode.. data = urllib.urlencode({"username":user, "password":pass})

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.