Tuesday, April 17, 2012

Network Handling Part 2

Hello Everyone, Lets now continue our Journey, with few more examples of Network Handling in Python.

First I would like to introduce you to geturl() of urllib Module

Lets Open up the Python Shell

>>> import urllib
>>> site = "http://microsoft.org"
>>> find = urllib.urlopen(site)
>>> find.geturl()
'http://www.microsoft.com/en-us/default.aspx'
>>> # geturl() tell us the redirected url

Another Function that you would like to know is urlretrieve(), which saves a copy of any webpage, but the only thing is that it would not display any images when you open up the copied html doc. but the external links on the copied web page would just work fine.

>>> urllib.urlretrieve('http://www.python.org', 'C:/files/python.html')

So the above line would save a copy of the website in C:/files named python.html

So , we have seen the basics of accessing the web pages with Python, there are some more functions which I will discuss on the next post.

Hope this was Interesting, and Don't forget to check my next Post.

Thank You!

0 comments:

Post a Comment