Date post: | 07-Dec-2014 |
Category: |
Software |
Upload: | navaneethan-naveen |
View: | 158 times |
Download: | 0 times |
WELCOME TO PYTHON SESSION 6WELCOME TO PYTHON SESSION 6
AGENDA
Urllib2 Module.
Urllib2 functions and handling methods.
What is Urllib2?
urllib2 is a Python module that can be used for fetching URLs.
It defines functions and classes to help with URL actions
What is the difference between urllib and urllib2?
urllib2 can accept a Request object to set the headers for a URL request
urllib accepts only a URL.
urllib provides the urlencode method which is used for the generation
of GET query strings, urllib2 doesn't have such a function.
Example
Simple urllib2 script
Download files with Urllib2
Get and Post Method
The request function under the urllib2 class accepts both url and parameter.
When you don't include the data (and only pass the url), the request being made is actually a GET request.
When you do include the data, the request being made is a POST request, where the url will be your post url, and the parameter will be http post content.
Get Method
Post Method
Reference url:
http://www.pythonforbeginners.com/urllib2/
THANK YOU