K
K
Kactus2020-07-12 03:38:56
Python
Kactus, 2020-07-12 03:38:56

How to log in to VK?

Goodnight. I need to take remixsid from VK cookies, they are set in the browser after authorization, but in the program only remixir=DELETED, remixlang=6, remixtst=DELETED, and remixstid=many numbers are set. How to make it get remixsid, authorization succeeds

import requests
import urllib
import json
import re
from bs4 import BeautifulSoup

email = ""
passw = ""

headers = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36", "cookie": "remixlhk=95e7a3b471fa495aa0;"}
content_main = requests.post('https://vk.com/login', headers=headers)
soup = BeautifulSoup(content_main.text, 'lxml')
ip_h = soup.find("input", attrs={'name':'ip_h', 'type':'hidden'})['value']
lg_h = soup.find("input", attrs={'name':'lg_h', 'type':'hidden'})['value']
params1 = {'act':'login', '_origin':'https://vk.com', 'ip_h':ip_h, 'lg_h':lg_h, 'email':email, 'pass':passw}
encoded_params1 = urllib.parse.urlencode(params1).encode('utf-8')
login_one = urllib.request.urlopen(urllib.request.Request("https://login.vk.com", encoded_params1, headers))
print(login_one.geturl())

q_hash = re.split(r'=', login_one.geturl())[6]
soup1 = BeautifulSoup(login_one.read(), 'lxml')
ip_h = soup1.find("input", attrs={'name':'ip_h', 'type':'hidden'})['value']
lg_h = soup1.find("input", attrs={'name':'lg_h', 'type':'hidden'})['value']
login_last_url = 'https://vk.com/login.php?act=login&role=fast&redirect=1&to=&s=1&__q_hash={q_hash}&ip_h={ip_h}&lg_h={lg_h}&email={email}&pass={passw}'
params2 = {'act':'login', 'role':'fast', 'redirect':1, 'to':'', 's':1, '__q_hash':q_hash, 'ip_h':ip_h, 'lg_h':lg_h, 'email':email, 'pass':passw}
encoded_params2 = urllib.parse.urlencode(params2).encode('utf-8')
login_last = urllib.request.urlopen(urllib.request.Request(login_last_url, encoded_params2, headers))
login_last2 = urllib.request.urlopen(urllib.request.Request(login_last_url, encoded_params2, headers))
print(login_last2.info())

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2020-07-12
@Kactus

At least - do not use requests.Session ()
What kind of error is that?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question