python 异步采集,网页爬虫编写 | 一步一步学python
python 异步采集对于大量的数据采集除了多线程,就只有异步来实现了
上一篇文章里我写了有关多线程的实现,对于异步的由于本人对python的学习还不是很深入还不能自己写出来,刚好看到一个篇使用twisted异步采集的文章,就搬过来给大家分享一下。Async Batching with Twisted: A Walkthrough
Example 1: Just a DefferedList
from twisted.internet import reactor from twisted.web.client import getPage from twisted.internet.defer import DeferredList def listCallback(results): print results def finish(ign): reactor.stop() def test(): d1 = getPage('http://www.google.com') d2 = getPage('http://yahoo.com') dl = DeferredList([d1, d2]) dl.addCallback(listCallback) dl.addCallback(finish) test() reactor.run()欢迎分享,转载请注明来源:内存溢出
评论列表(0条)