使用python请求向Messenger进行身份验证

时间:2019-09-27 21:56:55

标签: python-3.x authentication beautifulsoup python-requests

我想制作一个程序以连接到我的Messenger帐户。我在python中使用请求库和漂亮的汤,但我不知道如何进行身份验证。

我尝试发出get请求,将登录到Messenger时从chrome开发人员工具中看到的登录数据传递给我,但它没有连接。另外我也不知道如何查看任何调试信息。

headers = {
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) 
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/...
}

login_data = {
    'timezone': '...',
    'lgndim': '...',
    'lgnjs': '...',
    'email': '...',
    'pass': '...',
    'login': '...',
    'default_persistent': '...'
}

with requests.Session() as s:
    url = "https://www.messenger.com/login/"
    r = s.get(url, headers=headers)

    soup = BeautifulSoup(r.text, 'html5lib')

    login_data['initial_request_id'] = soup.find('input', attrs={'name': 
    "initial_request_id"})['value']
    login_data['jazoest'] = soup.find('input', attrs={'name': "jazoest"}) 
    ['value']
    login_data['lgnrnd'] = soup.find('input', attrs={'name': "lgnrnd"}) 
    ['value']
    login_data['lsd'] = soup.find('input', attrs={'name': "lsd"})['value']

     r = s.post(url, data=login_data, headers=headers)
     r.raise_for_status()

     with open("messenger_html.txt", "w", encoding="utf-8") as file:
         file.write(soup.prettify())

每次我看到创建的messenger_html.txt文件都是Messenger登录页面。也许我需要对Cookie做些事情?

0 个答案:

没有答案