标签:tab odi bing com import lib size bytes reactor
安装twisted模块
Linux:
pip3 install twisted
Window:
a. http://www.lfd.uci.edu/~gohlke/pythonlibs/#twisted, 下载:Twisted-17.1.0-cp35-cp35m-win_amd64.whl b. 进入文件所在目录 c. pip3 install Twisted-17.1.0-cp35-cp35m-win_amd64.whl
Twisted实例[小有问题]
from twisted.web.client import getPage # 专门用来发送HTTP请求的 from twisted.web.client import defer from twisted.internet import reactor # 循环等待用户请求的响应 def all_done(arg): reactor.stop() def callback(contents): print(contents) deferred_list = [] url_list = [‘http://www.bing.com‘, ‘http://www.baidu.com‘, ] for url in url_list: deferred = getPage(bytes(url, encoding=‘utf8‘)) # 加载url交给getPage() deferred.addCallback(callback) # 回调函数表示请求完成后,需要做的操作 # deferred_list.append(deferred) # # dlist = defer.DeferredList(deferred_list) # dlist.addBoth(all_done) reactor.run() # de
标签:tab odi bing com import lib size bytes reactor
原文地址:https://www.cnblogs.com/ftl1012/p/9424829.html