fork download
  1. import urllib2, re, urlparse
  2.  
  3. url = "http://2...content-available-to-author-only...h.hk/fag/res/1197446.html"
  4. htmllist = urllib2.urlopen(url).read()
  5. imgURLs = re.findall('img .*?src="(.*?)"', htmllist)
  6.  
  7. i=0
  8. while i<len(imgURLs):
  9. imgURL = urlparse.urljoin(url, imgURLs[i])
  10. img = urllib2.urlopen(imgURL).read()
  11. namefile = str(i)+".png"
  12. f = open(namefile,"wb")
  13. f.write(img)
  14. f.close()
  15. i+=1
Runtime error #stdin #stdout #stderr 0.04s 13240KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "prog.py", line 4, in <module>
  File "/usr/lib/python2.7/urllib2.py", line 154, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python2.7/urllib2.py", line 431, in open
    response = self._open(req, data)
  File "/usr/lib/python2.7/urllib2.py", line 449, in _open
    '_open', req)
  File "/usr/lib/python2.7/urllib2.py", line 409, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.7/urllib2.py", line 1227, in http_open
    return self.do_open(httplib.HTTPConnection, req)
  File "/usr/lib/python2.7/urllib2.py", line 1197, in do_open
    raise URLError(err)
urllib2.URLError: <urlopen error [Errno -2] Name or service not known>