1

A web page has 2 form fields

1:

<input type="text" maxlength="30" value="" name="poster" id="id_poster">

2:

<textarea name="content" cols="80" rows="20" id="id_content"></textarea>

Also it has a button:

<input type="submit" value="Submit your own idea!">

What I want is, through python to fill in the forms id_poster and id_content and then Submit. If possible, to take the webpage after submitting (to take the result).

Thank you all

1

2 Answers 2

7

Personally I prefer httplib2, you would have to install it. The library is a lot better than the one given that by python out of the box.

from httplib2 import Http
from urllib import urlencode
h = Http()
data = dict(id_poster="some_poster_id", id_content="some_content")
resp, content = h.request("http://example.org/form-handler", "POST", urlencode(data))

Then you can check the response with the resp

Sign up to request clarification or add additional context in comments.

Comments

4

You can do it like this (taken from this example):

import urllib
import urllib2

url = 'http://www.someserver.com/somepage.html'
values = {'id_poster' : 'some_poster_id',
          'id_content' : 'some_content'}

data = urllib.urlencode(values)
req = urllib2.Request(url, data)
response = urllib2.urlopen(req)
the_page = response.read()

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.