wikipedia pictures download example
This commit is contained in:
20
control/http_cli0.py
Normal file
20
control/http_cli0.py
Normal file
@@ -0,0 +1,20 @@
|
||||
# adaptado de:
|
||||
# https://github.com/feihong/tulip-talk/blob/master/examples/2-tulip-download.py
|
||||
|
||||
import asyncio
|
||||
import aiohttp
|
||||
|
||||
@asyncio.coroutine
|
||||
def download(url):
|
||||
response = yield from aiohttp.request('GET', url)
|
||||
for k, v in response.items():
|
||||
print('{}: {}'.format(k, v[:80]))
|
||||
|
||||
data = yield from response.read()
|
||||
print('\nReceived {} bytes.\n'.format(len(data)))
|
||||
|
||||
if __name__ == '__main__':
|
||||
loop = asyncio.get_event_loop()
|
||||
url = 'https://www.cia.gov/library/publications/the-world-factbook/geos/br.html'
|
||||
coroutine = download(url)
|
||||
loop.run_until_complete(coroutine)
|
||||
Reference in New Issue
Block a user