Created
February 5, 2024 06:57
-
-
Save OlegKorn/d06f38f48c6dde7d11c977dabee00db6 to your computer and use it in GitHub Desktop.
aiohttp requests ver.2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import httpx | |
import asyncio | |
import aiohttp | |
import os | |
from fp.fp import FreeProxy | |
THIS_DIR = os.path.dirname(os.path.realpath(__file__)).replace('\\', '/') | |
def open_file(fr, to): | |
with open(f'{THIS_DIR}/ordered', "r", encoding='utf-8') as num_lines: | |
text = [line.strip() for line in num_lines.readlines()[fr:to]] | |
return text | |
# pr = FreeProxy(country_id=['US', 'BR']).get() | |
async def fetch(session, url): | |
async with session.get(url) as response: #proxy=pr) as response: | |
return await response.text(), response.status | |
async def main(url): | |
async with aiohttp.ClientSession(connector=aiohttp.TCPConnector(ssl=False)) as session: | |
resp = await fetch(session, url) | |
print(url, resp[1]) | |
for num in range(0, 10000, 250): | |
fr = num | |
to = num + 250 | |
urls = [i.strip() for i in open_file(fr, to)] | |
print(fr, to) | |
try: | |
loop = asyncio.get_event_loop() | |
future = [asyncio.ensure_future(main(url)) for url in urls] | |
loop.run_until_complete(asyncio.wait(future)) | |
print('Sleeping 8...') | |
sleep(8) | |
except Exception as e: | |
print(e) | |
break | |
# sys.exit(1) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment