I have a PHP page that has 1 textbox and when I press on the submit button. My SQL is going to store this product name into my database. My question is; is it possible to send/post the product name using Python script that asks for 1 value and then use my PHP page to send it to my database? Thanks!
|
Check out the urllib and urllib2 modules. http://docs.python.org/library/urllib2.html http://docs.python.org/library/urllib.html Simply create a Request object with the needed data. Then read the response from your PHP service. |
|||
|
When testing, or automating websites using python, I enjoy using twill. Twill is a tool that automatically handles cookies and can read HTML forms and submit them. For instance, if you had a form on a webpage you could conceivably use the following code:
This would load the form, fill in the value, and submit it. |
|||||||||
|
I find http://www.voidspace.org.uk/python/articles/urllib2.shtml to be a good source of information about urllib2, which is probably the best tool for the job.
The encoding is actually done using urllib, and this supports HTTP POST. There is also a way to use GET, where you have to pass the data into urlencode. Don't forget to call read() though, otherwise the request won't be completed. |
|||
|
Yes. urllib2 is a nice Python way to form/send HTTP requests. |
|||
|
Just an addendum to @antileet's procedure, it works similarly if you're trying to do a HTTP POST request with a web-service-like payload, except you just omit the urlencode step; i.e.
|
|||
|