I have 227 links where I am trying to fetch the html. I am using Python and jupyter notebook. I noticed that my asynchronous requests using 'aiohttp' and 'asyncio' library was taking the same time as when using normal "requests" library which i think is synchronous
My async request code using 'aiohttp'. 'asyncio':
import asyncio
import aiohttp
# using jupyter hence initializing nest_asyncio
import nest_asyncio
nest_asyncio.apply()
all_links = [] # contains all the links to the website
htmls = []
try:
async def main():
try:
async with aiohttp.ClientSession() as session:
for link in all_links:
async with session.get(link) as response:
html = await response.text()
htmls.append(html)
except Exception as e:
print(e)
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
except Exception as e:
print(e)
# it takes 1min 9.2s to complete 227 requests
this is my code for synchronous requests operation
import requests
for link in all_links:
value = requests.get(link)
# it takes 1min 9.5s to complete 227 requests
here are some of the links where I am making requests if anyone wants to try
https://www.eslcafe.com/postajob-detail/great-private-and-public-school-positions-all?koreasearch=&koreapageno=1&koreapagesize=300&chinasearch=&chinapageno=1&chinapagesize=300&internationalsearch=&internationalpageno=1&internationalpagesize=300
https://www.eslcafe.com/postajob-detail/apply-now-for-teaching-job-in-korea-china-hig-14?koreasearch=&koreapageno=1&koreapagesize=300&chinasearch=&chinapageno=1&chinapagesize=300&internationalsearch=&internationalpageno=1&internationalpagesize=300
https://www.eslcafe.com/postajob-detail/full-time-esl-teacher-wanted-2?koreasearch=&koreapageno=1&koreapagesize=300&chinasearch=&chinapageno=1&chinapagesize=300&internationalsearch=&internationalpageno=1&internationalpagesize=300
https://www.eslcafe.com/postajob-detail/teachers-for-march-seoul-good-locations-acros?koreasearch=&koreapageno=1&koreapagesize=300&chinasearch=&chinapageno=1&chinapagesize=300&internationalsearch=&internationalpageno=1&internationalpagesize=300
https://www.eslcafe.com/postajob-detail/asap-2023-fall-semester-open-full-time-trustw-4?koreasearch=&koreapageno=1&koreapagesize=300&chinasearch=&chinapageno=1&chinapagesize=300&internationalsearch=&internationalpageno=1&internationalpagesize=300