dchrastil / ScrapedIn

A tool to scrape LinkedIn without API restrictions for data reconnaissance
1.02k stars 135 forks source link

Could not authenticate to linkedin #39

Open astronautjez07 opened 2 months ago

astronautjez07 commented 2 months ago

[Fatal] Could not authenticate to linkedin. Set credentials in your environment variables

syedbilalalam1 commented 1 day ago

I think it's an issue with the new Linkedin authentication system. I've edited the code a bit and it works for me now.

Change the authentication function to this:

 # Authentication Fix
 def authenticate():
      print("[Info] Initiating LinkedIn authentication...")

# Use credentials from config file instead of environment variables
username = config.linkedin['username']
password = config.linkedin['password']

if not username or not password:
    raise ValueError("LinkedIn username and password must be set in config.py")

url = "https://www.linkedin.com/checkpoint/lg/login-submit"
csrf = "00000000-8a9a-474e-8bc1-6f10272b5fe6"
postdata = {
    'session_key': username,
    'session_password': password,
    'loginCsrfParam': csrf,
}
cookies = {'bcookie': 'v=2&%s' % csrf}

# Login Request
r = requests.post(url, postdata, cookies=cookies, allow_redirects=False)

try:
    session = r.cookies.get('li_at')
    if session:
        print(f"[Info] Obtained new session: {session[:25]}...")
        return {'li_at': session}
    else:
        raise RuntimeError("[Fatal] Could not authenticate to LinkedIn.")
except Exception as e:
    raise RuntimeError(f"[Fatal] Authentication failed: {e}")

Then you can replace the config with your email and password. It should work then! :)