15.04.2013 Views

Core Python Programming (2nd Edition)

Core Python Programming (2nd Edition)

Core Python Programming (2nd Edition)

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

net_loc can be broken down into several more components, some required, others optional. The net_loc<br />

string looks like this:<br />

user:passwd@host:port<br />

These individual components are described in Table 20.2.<br />

Table 20.2. Network Location Components<br />

net_loc Component Description<br />

user User name or login<br />

passwd User password<br />

host Name or address of machine running Web server [required]<br />

port Port number (if not 80, the default)<br />

Of the four, the host name is the most important. The port number is necessary only if the Web server<br />

is running on a different port number from the default. (If you aren't sure what a port number is, go<br />

back to Chapter 16.)<br />

User names and perhaps passwords are used only when making FTP connections, and even then they<br />

usually aren't necessary because the majority of such connections are "anonymous."<br />

<strong>Python</strong> supplies two different modules, each dealing with URLs in completely different functionality and<br />

capacities. One is urlparse, and the other is urllib. We will briefly introduce some of their functions<br />

here.<br />

20.2.2. urlparse Module<br />

The urlparse module provides basic functionality with which to manipulate URL strings. These functions<br />

include urlparse(), urlunparse(), and urljoin().<br />

urlparse.urlparse()<br />

urlparse() breaks up a URL string into some of the major components described above. It has the<br />

following syntax:<br />

urlparse(urlstr, defProtSch=None, allowFrag=None)<br />

urlparse() parses urlstr into a 6-tuple (prot_sch, net_loc, path, params, query, frag). Each of these<br />

components has been described above. defProtSch indicates a default network protocol or download

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!