Cookie 模拟登陆 实例

import urllib.request
import re

def urlopen(Cookie,url):

head = {}
head['Accept']='text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8'

head['Accept-Language']='zh-CN,zh;q=0.9'

head['Cache-Control']='max-age=0'

head['Connection']=' keep-alive'

# Cookie 这个要改不同 

head['Cookie']= Cookie



head['Host']='jxjyxuexi.chinaacc.com'

head['Referer']='http://jxjyxuexi.chinaacc.com/Sys/Login/?Area=5115,/guangxi/guangxiqu/Home%2Easpx&code=0&msg=succ&ssouid=53703784&username=gx150804112806282&domain=%40chinaacc%2Ecom&sid=6qro0195089vvrfrdq80hdkn34'

head['Upgrade-Insecure-Requests']='1'

head['User-Agent']='Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36'

req = urllib.request.Request(url,headers = head)
#加入headers

'''
data = {}

data['username']='350124199012161088'
data['password']='huang1028' 

print(data)
#加入的表单数据

data = urllib.parse.urlencode(data).encode('utf-8')
#表单数据输换
#encoding='gbk'

'''

html = urllib.request.urlopen(req)
#访问时加入了headers 和表单data

html = html.read()

return html

def deng():

url = input('请输入学习中心链接:')

Cookie = input('请输入 ‘Cookie’ :')


html = urlopen(Cookie,url)

html =html.decode('utf-8')

cont = re.findall(r'退出登录',html)

if len(cont)==1:
    
    print(cont)

    print('已经登陆完成')

else:

    print('没有登录成功')
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值