标签:
>>> import urllib.request >>>local_filename,headers=urllib.request.urlretrieve(‘http://python.org/‘) >>> html = open(local_filename) >>> html.close()
#coding:utf-8 from urllib.request import urlretrieve def firstNonBlank(lines): for eachLine in lines: if not eachLine.strip(): continue else: return eachLine def firstLast(webpage): f=open(webpage,encoding=‘utf-8‘) lines=f.readlines() f.close() print(firstNonBlank(lines)) lines.reverse() print(firstNonBlank(lines)) def download(url=‘http://www.baidu.com‘,process=firstLast): try: retval=urlretrieve(url)[0] except IOError: retval=None if retval: process(retval) if __name__=="__main__": download()
标签:
原文地址:http://www.cnblogs.com/itdyb/p/5411723.html