cookiejar获取cookie

def login_cookie(self,username,pwd,formhash):
    LOGIN_URL = 'https://www.yaozh.com/login'
    values = {'type': '0',
              'username': username,
              'pwd': pwd,
              'country': '86_zh-CN',
              'mobile': '',
              'vcode': '',
              'pincode': '',
              'formhash': formhash,
              'backurl': 'https%3A%2F%2Fdb.yaozh.com%2F'}
    postdata = urllib.parse.urlencode(values).encode()
    headers = {
        'Accept': '*/*', 'Accept-Encoding': 'gzip, deflate, br',
        'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
        'Connection': 'keep-alive',
        'Content-Length': '154',
        'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
        # 'Cookie': 'PHPSESSID=p0gspsj65qantb5s3akujf5526; SL_GWPT_Show_Hide_tmp=1; SL_wptGlobTipTmp=1; UtzD_f52b_saltkey=It9n0t3p; UtzD_f52b_lastvisit=1610081965; _ga=GA1.1.1610179621.1610085575; _gid=GA1.2.1404801520.1610335847; Hm_lvt_65968db3ac154c3089d7f9a4cbb98c94=1610086483,1610098940,1610099878,1610335847; think_language=zh-CN; acw_tc=707c9f9416103455137662279e75c17c9d85bd6d24ac08da03807ee5490018; _ga=GA1.2.1610179621.1610085575; yaozh_userId=1029059; yaozh_uidhas=1; yaozh_mylogin=1610346593; UtzD_f52b_ulastactivity=1609988952%7C0; yaozh_logintime=1610346665; yaozh_user=1029059%09qwer1234%EF%BC%81; yaozh_jobstatus=kptta67UcJieW6zKnFSe2JyYnoaSZ5dulZmeg26qb21rg66flM6bh5%2BscZJpbIXW2cbWlZNqmSQh5YecpnFuclPNmqSnwKrO0Z5ZnKtslJW540681a604a1c1515Ba12692f98e174Ccg5WakmeYaZqbnJFVcqhyZZtbpZzOm4efrHGSa2yFlpiSlJeVbZtrm5ebmVVysg%3D%3D7e98a6e6f1762de0e276a5a3f53d7c2b; db_w_auth=847469%09qwer1234%EF%BC%81; UtzD_f52b_lastact=1610346666%09uc.php%09; UtzD_f52b_auth=fe74N8JJHTW6wF%2B8mqbcYswhZnVgoxXvWuJEmyfRB9iHfKSNwqYR7HW5XpSocAGZLWRlAwn%2BUQBNpf2BuFF3dPsXDBo; Hm_lpvt_65968db3ac154c3089d7f9a4cbb98c94=1610346670',
        'Host': 'www.yaozh.com',
        'Sec-Fetch-Dest': 'empty',
        'Sec-Fetch-Mode': 'cors',
        'Sec-Fetch-Site': 'same-origin',
        'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36',
        'X-Requested-With': 'XMLHttpRequest'
    }
    cookiejar = CookieJar()
    handler = request.HTTPCookieProcessor(cookiejar)
    opener = urllib.request.build_opener(handler)
    req = urllib.request.Request(LOGIN_URL, postdata, headers)
    try:
        response = opener.open(req)
    except urllib.error.URLError as e:
        print(e.reason)
        return ''
    if response.status == 200:
        cookie_list = []
        for i in cookiejar:
            cookie_list.append('{}={}'.format(i.name, i.value))
        return '; '.join(cookie_list)
    else:
        return ''

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值