python模块整理

一、time模块:import time

  1、time.sleep(3)   #单位为妙

二、urllib

  1、传递一个url地址得到其html内容:from urllib.request import urlopen

from  urllib.request  import urlopen
res = urlopen('http://crm.oldboyedu.com').read()   #打印出的是16进制
print(res.decode('utf-8'))     #  转换为汉字

def index(url):
    def get():
        old_boy= urlopen(url).read()
        return old_boy
    return get

old_boy = index('http://crm.oldboyedu.com')  
print(old_boy.__closure__[0].cell_contents)   #每一个函数都有一个__closure__函数,如果是闭包函数,则其cell_contents方法返回闭包的值:http://crm.oldboyedu.com
print(old_boy().decode('utf-8'))

 

原文地址:https://www.cnblogs.com/wangkc/p/6901322.html