from concurrent.futures import ThreadPoolExecutor import requests, time def get(url): print('GET %s'%url) resposn = requests.get(url) time.sleep(3) return {'url':url, 'content':resposn.text} def parse(res): res = res.result() print('%s parse is %s'%(res['url'], len(res['content']))) if __name__ == '__main__': urls = ['https://home.firefoxchina.cn/', 'https://download.csdn.net/download/lianxinhai/10938887', 'http://book.luffycity.com/python-book/di-7-zhang-bing-fa-bian-cheng/7xiaojie.html'] pool = ThreadPoolExecutor(2) for url in urls: pool.submit(get, url).add_done_callback(parse) '''使用异步调用实现抓取网络源码'''