Skip to content

Instantly share code, notes, and snippets.

@lzcdev
Created March 13, 2018 08:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lzcdev/e215870dd3430eb184beb5015f0b319d to your computer and use it in GitHub Desktop.
Save lzcdev/e215870dd3430eb184beb5015f0b319d to your computer and use it in GitHub Desktop.
html_downloader.py下载器
import urllib2
class HtmlDownloader(object):
def download(self, url):
if url is None:
print 'url is None'
return None
try:
response = urllib2.urlopen(url, timeout=10)
if response.getcode() != 200:
print 'false'
return None
print 'success'
except:
print 'timeout'
return response.read()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment