Dec-01-2016, 08:37 PM
"""
Create a function called
a fully qualified URL (e.g. https://www.yahoo.com/).
The function must:
1. Save the contents returned by that URL (the HTTP response body) into a
file. The filename must be the same as the FQDN part of input URL. The file
must be created in the current working directory (CWD).
2. The value of the Content Type HTTP header must be returned as the function
result, regardless of the actual HTTP code.
3. The function documentation should read:
Download the contents of an URL and return response's mimetype
HINT: Look into urlparse.urlparse() for FQDN retrieval.
For example:
wget('https://yahoo.com/') -> 'text/html'
# Creates/Rewrites a file called yahoo.com with the contents of yahoo.com
I'm getting this error
Create a function called
wget
, which takes a single argument -a fully qualified URL (e.g. https://www.yahoo.com/).
The function must:
1. Save the contents returned by that URL (the HTTP response body) into a
file. The filename must be the same as the FQDN part of input URL. The file
must be created in the current working directory (CWD).
2. The value of the Content Type HTTP header must be returned as the function
result, regardless of the actual HTTP code.
3. The function documentation should read:
Download the contents of an URL and return response's mimetype
HINT: Look into urlparse.urlparse() for FQDN retrieval.
For example:
wget('https://yahoo.com/') -> 'text/html'
# Creates/Rewrites a file called yahoo.com with the contents of yahoo.com
import urllib2 from urlparse import urlparse def wget(*args): u = args obj = urlparse(url) fn = obj.netloc response = urllib2.urlopen(u) with open('fn','w') as f: f.write(response(read)) f.close url = 'http://yahoo.com/' wget(url)What am i doing wrong ...
I'm getting this error
Traceback (most recent call last): File "wget.py", line 24, in <module> import urllib2 File "C:\Anaconda2\lib\urllib2.py", line 94, in <module> import httplib File "C:\Anaconda2\lib\httplib.py", line 72, in <module> import socket File "C:\Anaconda2\lib\socket.py", line 47, in <module> import _socket ImportError: DLL load failed: %1 is not a valid Win32 application.