Explanation of the specific application method of the Python submission form

Source: Internet
Author: User

The Python programming language is a powerful object-oriented language that helps us easily implement many functional requirements. Here, we can first master the related operation methods for submitting forms in Python, hoping to help you in practical application.

Python form submission code example:

 
 
  1. #-*-Coding: cp936 -*-
  2. Import urllib2, urllib, sys
  3. Http://www.baidu.com/s"
  4. Search = [('w', 'python'), ('cl', '3')]
  5. GetString = url + "? "+ Urllib. urlencode (search)
  6. Req = urllib2.Request (getString)
  7. Fd = urllib2.urlopen (req)
  8. While 1:
  9. Data = fd. read (1, 1024)
  10. If not len (data ):
  11. Break
  12. Sys. stdout. write (data)
  13. *************************************
  14. #-*-Coding: cp936 -*-
  15. Import urllib2, urllib, sys
  16. """
  17. Use POST to submit Form data
  18. 1. encoding or using urlencode
  19. 2. Do not use string connection
  20. 3. Use the data parameter of urlopen
  21. The example cannot run because www.google.com only supports the GET method and does not provide the POST method.
  22. """
  23. Url = "http://www.google.com/search"
  24. Search = urllib. urlencode ([('Q', 'python')])
  25. Req = urllib2.Request (url)
  26. Fd = urllib2.urlopen (req, search)
  27. While 1:
  28. Data = fd. read (1, 1024)
  29. If not len (data ):
  30. Break
  31. Sys. stdout. write (data)

The above describes how to submit a Python form.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.