def fetchData(url, callback = pd.Xm, params=None):
#set request url and parameters here or you can pass from outside.
con = aiohttp.TCPConnector(limit=config.REQ_AMOUNTS)
s = aiohttp.ClientSession(headers = config.HEADERS, connector=con)
#use s.** request a webside will keep-alive the connection automaticaly,
#so you can set multi request here without close the connection
#while in the same domain.
#i.e.
#await s.get('***/page1')
#await s.get('***/page2')
########################################################################
r=yield from s.get(url, params = params)
#here the conection closed automaticly.
data = yield from r.text(encoding='utf-8')
yield from callback(data)
r.close()
评论列表
文章目录