Python Programming/Internet

The urllib module which is bundled with python can be used for web interaction. This module provides a file-like interface for web urls.

Getting page text as a string
An example of reading the contents of a webpage

Processing page text line by line:

Get and post methods can be used, too.

Downloading files
To save the content of a page on the internet directly to a file, you can read it and save it as a string to a file object This will download the file from here and save it to a file "pythonbook.pdf" on your hard drive.

Other functions
The urllib module includes other functions that may be helpful when writing programs that use the internet: The urlencode function, described above converts a dictionary of key-value pairs into a query string to pass to a URL, the quote and quote_plus functions encode normal strings. The quote_plus function uses plus signs for spaces, for use in submitting data for form fields. The unquote and unquote_plus functions do the reverse, converting urlencoded text to plain text.

Email
With Python, MIME compatible emails can be sent. This requires an installed SMTP server.

This sends the sample message from 'sender@example.com' to 'receiver@example.com'.