Web Access Functions¶
import introcs
With the elimination of urllib2
and the move to Unicode, Python 3 has made web connections
a little more difficult for students just starting out. These functions are intended to
simplify things once again.
urlread¶
- introcs.urlread(url)¶
Opens the web page at
url
and returns its contents.If there is no web page at url a
URLError
. If the url is malformed, it raises aValueError
instead.- Parameters
url (
str
) – The web page url- Returns
The contents of the web page at
url
if it exists.- Return type
str
urlinfo¶
- introcs.urlinfo(url)¶
Returns the headers for the web page at
url
.The headers are returned as a dictionary.
If there is no web page at url a
URLError
. If the url is malformed, it raises aValueError
instead.- Parameters
url (
str
) – The web page url- Returns
The headers for the web page at
url
if it exists.- Return type
dict