linkedin-api icon indicating copy to clipboard operation
linkedin-api copied to clipboard

A solution to constant challenge step

Open gokaybiz opened this issue 1 year ago • 6 comments

from requests.cookies import RequestsCookieJar, create_cookie
from linkedin_api.cookie_repository import CookieRepository
import json

cookies = json.load(open('./cookies.json')) # Path of exported cookie via https://www.editthiscookie.com/

cookie_jar = RequestsCookieJar()

for cookie_data in cookies:
    cookie = create_cookie(
        domain=cookie_data["domain"],
        name=cookie_data["name"],
        value=cookie_data["value"],
        path=cookie_data["path"],
        secure=cookie_data["secure"],
        expires=cookie_data.get("expirationDate", None),
        rest={
            "HttpOnly": cookie_data.get("httpOnly", False),
            "SameSite": cookie_data.get("sameSite", "unspecified"),
            "HostOnly": cookie_data.get("hostOnly", False),
        }
    )
    cookie_jar.set_cookie(cookie)


new_repo = CookieRepository()
new_repo.save(cookie_jar, 'email_or_username')

Log in to your linkedin account in the browser and export your cookies with EditThisCookie, then save it as cookie.json. That's all.

gokaybiz avatar Aug 10 '23 12:08 gokaybiz

@gokaybiz It works fine. But problem is cookie expire time. How to automate the process?

russell310 avatar Sep 05 '23 10:09 russell310

@gokaybiz It works fine. But problem is cookie expire time. How to automate the process?

In line 16, it should be adding the expiration time. What exactly is the problem you are having?

Edit: Ah, now I see what you mean. You can use Selenium to perform web login and dump cookies. But you will probably encounter captcha issue again. So sending an email to yourself when it throws an error and checking the status manually will be the least troublesome method.

gokaybiz avatar Sep 05 '23 12:09 gokaybiz

I've done the automated login process, it used to work until recently when Linkedin changed their policies, i'd recommend just creating a notification system and logging error cleanly so as soon as the cookies expire you can change them as they last for a few months

SIF-FCHIARI avatar Sep 05 '23 14:09 SIF-FCHIARI

Already use this manual fixing. But need automation. Can you describe process for selenium in server? As headless how can we put code? Also sometime puzzle came instead of code

russell310 avatar Sep 05 '23 14:09 russell310

How long do the cookies typically take to expire? @gokaybiz

sim1029 avatar Mar 25 '24 20:03 sim1029

@sim1029 Well, it depends on your actions. If you are not spamming it takes ~2 months

gokaybiz avatar Apr 08 '24 14:04 gokaybiz