美文网首页
新浪微博扫码登录获取Cookie

新浪微博扫码登录获取Cookie

作者: 无量儿 | 来源:发表于2021-11-23 09:48 被阅读0次

    import requests, json
    from io import BytesIO
    from PIL import Image

    qrAllUrl = 'https://login.sina.com.cn/sso/qrcode/image?entry=weibo&size=180&callback=STK_' + str(int(time.time()))

    print(requests.get(qrAllUrl).text)

    qrJson = json.loads(re.findall(r'([)]', requests.get(qrAllUrl).text)[0])['data']

    print(qrJson)

    qrUrl = qrJson.get('image')
    qrId = qrJson['qrid']
    qrEcho = BytesIO(requests.get('https:' + qrUrl).content)
    Image.open(qrEcho).show() # 展示二维码
    qrCheckUrl = 'https://login.sina.com.cn/sso/qrcode/check?entry=sso&qrid=' + qrId + '&callback=STK_' + str(int(time.time()))
    qrCheckResponse = ''
    i = 0
    while 'succ' not in qrCheckResponse:
    i += 1
    print('第{}次查看是否成功请求...'.format(i))
    qrCheckResponse = requests.get(qrCheckUrl).text
    time.sleep(2)
    altUrl = json.loads(re.findall(r'([)]', qrCheckResponse)[0])['data']['alt']
    coreUrl = 'https://login.sina.com.cn/sso/login.php?entry=qrcodesso&returntype=TEXT&crossdomain=1&cdult=3&domain=weibo.com&alt=' + altUrl + '&savestate=3&callback=STK_' + str(time.time())
    print(coreUrl)
    loginUrl = requests.get(coreUrl).headers
    print(loginUrl)
    weiboCookies = dict(loginUrl)['Set-Cookie']
    print(weiboCookies)
    print('SUB=' + re.findall(r'SUB=(.*?);', weiboCookies)[0])

    相关文章

      网友评论

          本文标题:新浪微博扫码登录获取Cookie

          本文链接:https://www.haomeiwen.com/subject/pyxwtrtx.html