Crazy_yiner 发表于 2013-1-1 22:34:05

Python标准库学习笔记 urllib模块

<div id="cnblogs_post_body">利用缓存实现简单的获取
<div class="cnblogs_Highlighter">import urllibimport osdef reporthook(blocks_read,block_size,total_size):    if not blocks_read:      print 'Connection opened'      return    if total_size < 0:      print 'Read %d blocks ( %d bytes ) '%(blocks_read,blocks_read*block_size)    else:      amount_read = blocks_read*block_size      print 'Read %d blocks,or %d / %d'%\      (blocks_read,amount_read,total_size)try:    filename,msg = urllib.urlretrieve('http://zt.xiaomi.com/bbszt/rom/miuiv4_ics7.0/miuiV4_Mioneplus_ICS7.0_4.0_fastboot_dj8428bjkq.exe',    reporthook=reporthook)      print   print 'File:',filename    print 'Headers'    print msg    print 'File exists before cheanup',os.path.exists(filename)    finally:    #urllib.urlcleanup()      print ' File still exists:', os.path.exists(filename)
页: [1]
查看完整版本: Python标准库学习笔记 urllib模块