+ All Categories
Home > Software > Python session 6

Python session 6

Date post: 07-Dec-2014
Category:
Upload: navaneethan-naveen
View: 158 times
Download: 0 times
Share this document with a friend
Description:
python program
Popular Tags:
12
WELCOME TO PYTHON SESSION 6 WELCOME TO PYTHON SESSION 6
Transcript
Page 1: Python session 6

WELCOME TO PYTHON SESSION 6WELCOME TO PYTHON SESSION 6

Page 2: Python session 6

AGENDA

Urllib2 Module.

Urllib2 functions and handling methods.

Page 3: Python session 6

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

Page 4: Python session 6

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.

Page 5: Python session 6

Example

Page 6: Python session 6

Simple urllib2 script

Page 7: Python session 6

Download files with Urllib2

Page 8: Python session 6

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.

Page 9: Python session 6

Get Method

Page 10: Python session 6

Post Method

Page 11: Python session 6

Reference url:

http://www.pythonforbeginners.com/urllib2/

Page 12: Python session 6

THANK YOU


Recommended