jachinlin / geektime_dl

把极客时间装进 Kindle
https://jachinlin.github.io/geektime_dl
1.37k stars 356 forks source link

建议增加cookie登陆机制 #80

Closed YaoXuanZhi closed 2 years ago

YaoXuanZhi commented 3 years ago

这样可以阅读打包两不误

ysjiang4869 commented 3 years ago

这样可以阅读打包两不误

可以参考以下修改gk_apis.py文件的login方法,使用自定义的cookie 登录时,随意输入任意的手机号密码即可

@synchronized()
def _login(self) -> None:
    """登录"""
    url = 'https://account.geekbang.org/account/ticket/login'

    headers = {
        'Accept': 'application/json, text/plain, */*',
        'Accept-Language': 'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',  # noqa: E501
        'Host': 'account.geekbang.org',
        'Referer': 'https://account.geekbang.org/signin?redirect=https%3A%2F%2Fwww.geekbang.org%2F',  # noqa: E501
    }

    data = {
        "country": self._area,
        "cellphone": self._account,
        "password": self._password,
        "captcha": "",
        "remember": 1,
        "platform": 3,
        "appid": 1
    }

    # change code bellow
    rawdata = 'your cookie string'
    cookie = SimpleCookie()
    cookie.load(rawdata)

    # Even though SimpleCookie is dictionary-like, it internally uses a Morsel object
    # which is incompatible with requests. Manually construct a dictionary instead.
    cookies = {}
    for key, morsel in cookie.items():
        cookies[key] = morsel.value
    # comment this line
    # resp = self._post(url, data, headers=headers)
    # use your own cookie
    self._cookies = cookies
YaoXuanZhi commented 3 years ago

好的,我试下啦