Skip to content

Instantly share code, notes, and snippets.

@tinytengu
Created June 18, 2021 18:53
Show Gist options
  • Save tinytengu/6af1cea1caef4529b21f47a85afd94d2 to your computer and use it in GitHub Desktop.
Save tinytengu/6af1cea1caef4529b21f47a85afd94d2 to your computer and use it in GitHub Desktop.
memz.fun authorization implementation
import re
from vk_api import VkApi
from vk_api.exceptions import VkApiError
from bs4 import BeautifulSoup
class MemzAuth:
OAUTH_URL = 'https://oauth.vk.com/authorize?client_id=7877542&redirect_uri=https://memz.fun/signin.php&display=page'
GRANT_REGEX = r'(https:\/\/login\.vk\.com\/\?act=grant_access&client_id=7877542.+?\.php)'
def __init__(self, login, password):
self.login = login
self.password = password
self.vk = VkApi(self.login, self.password, auth_handler=self._vk_2fa_handler)
@property
def session(self):
return self.vk.http
def auth(self):
self.vk.auth()
response = self.vk.http.get(self.OAUTH_URL)
link = re.search(self.GRANT_REGEX, response.text)
# Доступ приложению Memz к аккаунту ВКонтакте ещё не разрешён, поэтому разрешим
if link:
self.vk.http.get(link.group(1))
def _vk_2fa_handler(self):
return input("Введите код 2FA: "), True
def main():
ma = MemzAuth('логин', 'пароль')
try:
ma.auth()
except VkApiError as ex:
print(f'Не удалось авторизоваться ВКонтакте ({ex})')
return
response = ma.session.get('https://memz.fun')
bs = BeautifulSoup(response.content, 'html.parser')
nametag = bs.find('div', class_='user-profile__right-name')
print(f'Авторизован на memz, как {nametag.text}')
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment