As part of my quest to become better at Python I am now attempting to sign in to a website I frequent, send myself a private message, and then sign out. So far, I’ve managed to sign in (using urllib, cookiejar and urllib2). However, I cannot work out how to fill in the required form to send myself a message.
The form is located at /messages.php?action=send. There’s three things that need to be filled for the message to send: three text fields named name, title and message. Additionally, there is a submit button (named “submit”).
How can I fill in this form and send it?
just replace
http://www.abc.com/messages.php?action=sendwith the url where your form is being submittedreply to your comment: if the url is the url where your form is located, and you need to do this just for one website, look at the source code of the page and find
and put this address as parameter for
urllib2.urlopenAnd you have to realise what
submitbutton does.It just send a
Httprequest to the url defined byactionin the form.So what you do is to simulate this request with
urllib2