Logging in to LinkedIn with python requests sessions

前端 未结 5 1313
傲寒
傲寒 2020-12-02 19:57

I\'m trying to log into LinkedIn using Python requests:

import sys
import requests
from BeautifulSoup import BeautifulSoup


payload={
    \'session-key\' :          


        
5条回答
  •  一个人的身影
    2020-12-02 20:16

    2019 Version.

    Slightly revised version working that takes into account the new structure of the page to find the connection cookie and adds the trk parameter.

    import requests
    from bs4 import BeautifulSoup
    
    email = ""
    password = ""
    
    client = requests.Session()
    
    HOMEPAGE_URL = 'https://www.linkedin.com'
    LOGIN_URL = 'https://www.linkedin.com/uas/login-submit'
    
    html = client.get(HOMEPAGE_URL).content
    soup = BeautifulSoup(html, "html.parser")
    csrf = soup.find('input', {'name': 'loginCsrfParam'}).get('value')
    
    login_information = {
        'session_key': email,
        'session_password': password,
        'loginCsrfParam': csrf,
        'trk': 'guest_homepage-basic_sign-in-submit'
    }
    
    client.post(LOGIN_URL, data=login_information)
    
    response = client.get('')
    

提交回复
热议问题