Advertisement
opexxx

getfavicon.py

Jun 6th, 2014
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.87 KB | None | 0 0
  1. #!/usr/bin/python
  2. # Copyright (c) 2009 Denis Bilenko. See LICENSE for details.
  3. """Spawn multiple workers and wait for them to complete"""
  4.  
  5. ursl = []
  6. urls = lines = ['http://www.' + line.strip() for line in open('urllist.txt')]
  7.  
  8. import gevent
  9. from gevent import monkey
  10.  
  11. # patches stdlib (including socket and ssl modules) to cooperate with other greenlets
  12. monkey.patch_all()
  13.  
  14. import urllib2
  15. from socket import setdefaulttimeout
  16. setdefaulttimeout(30)
  17.  
  18. def print_head(url):
  19.      print ('Starting %s' % url)
  20.      url = url + '/favicon.ico'
  21.      try:
  22.          data = urllib2.urlopen(url).read()
  23.          except Exception, e:
  24.          print 'error', url, e
  25.          return
  26.  
  27.     fn = 'icons/' + url[+11:].replace("/", "-")
  28.     myFile = file(fn, 'w')
  29.     myFile.write(data)
  30.     myFile.close()
  31.  
  32. jobs = [gevent.spawn(print_head, url) for url in urls]
  33.  
  34. gevent.joinall(jobs)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement