Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- try:
- import aiohttp
- except ModuleNotFoundError:
- print("aiohttp not found. Use 'pip3 install aiohttp' in console to fix it.")
- import asyncio
- import argparse
- def get_arg():
- parser = argparse.ArgumentParser()
- parser.add_argument('-f', '--file', nargs='?')
- parser.add_argument('-i', '--id', nargs='?')
- parser.add_argument('-s', '--start', default=1, nargs='?')
- parser.add_argument('-e', '--end', default=1000000000, nargs='?')
- parser.add_argument('-v', action='store_const', const=True)
- return parser
- result = []
- headers = {
- 'Accept': "text/html,application/xhtml+xm…plication/xml;q=0.9,*/*;q=0.8",
- "Accept-Encoding": "gzip, deflate, br",
- "Accept-Language": "ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3",
- "Cache-Control": "max-age=0",
- "Connection": "keep-alive",
- "Host": "vk.com",
- "Upgrade-Insecure-Requests": "1",
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; …) Gecko/20100101 Firefox/58.0"
- }
- async def request(i):
- async with aiohttp.ClientSession() as session:
- for n in i:
- response = await session.get('https://vk.com/doc{id}_{i}'.format(id=id, i=str(n).zfill(9)),
- headers=headers)
- if not response.headers.get('x-frame-options'):
- print(response.url)
- result.append(str(response.url))
- response.close()
- if namespace.v:
- print(response.url, response.status)
- async def task(it):
- futures = [request(i) for i in zip(*[iter(it)]*100 )]
- for i, future in enumerate(asyncio.as_completed(futures)):
- res = await future
- async def more_task(itt):
- futures = [task(i) for i in zip(*[iter(range((itt-1)*1000, itt*1000))]*100)]
- for i, future in enumerate(asyncio.as_completed(futures)):
- res = await future
- if __name__ == '__main__':
- try:
- parser = get_arg()
- namespace = parser.parse_args(sys.argv[1:])
- global id
- if namespace.id:
- id = namespace.id
- else:
- id = input('Input Id: ')
- ioloop = asyncio.get_event_loop()
- [ioloop.run_until_complete(more_task(i)) for i in range(1,10000000)]
- ioloop.close()
- except KeyboardInterrupt:
- for item in result:
- print(item)
- else:
- print('\n There is nothing')
- finally:
- if namespace.file:
- with open(str(namespace.file), 'w') as file:
- for line in result:
- file.write(line)
Advertisement
Add Comment
Please, Sign In to add comment